0 Replies Latest reply on Mar 7, 2017 4:11 PM by Lebron James

    createQuery not working but createNativeQuery works

    Lebron James Newbie

      Hi, guy, I have a very strange problem.


      I am setting up some endpoints in my application and I have an endpoints like this:

      public class IOConfigurationEndPoint {
        private static IOConfigurationDAO ioConfigurationDAO;
        public Response getAllIoConfigurations() {
          ioConfigurationDAO = new IOConfigurationDAO();
          List<IOConfiguration> list = ioConfigurationDAO.findAllIOConfiguration();
          return Response.status(Response.Status.OK).entity(list).build();

      The idea is that I need to get all the information "IO Configuration" from the table, and I have 32 rows in a table called "IO_CONFIGURATION", the pojo for this entity is like this:

      @Table(name = "IO_CONFIGURATION",
          indexes = {@Index(columnList = "CHANNEL_NAME", name = "CHANNEL_NAME")})
      public class IOConfiguration implements Serializable {
        private static final long serialVersionUID = 7542743172221933818L;
        @GenericGenerator(name = "IOConfiguration", strategy = "uuid")
        @GeneratedValue(generator = "IOConfiguration")
        @Column(name = "IO_CONFIGURATION_ID")
        private String ioConfigurationId;
        @Field(analyze = Analyze.NO)
        @Column(name = "CHANNEL_NAME")
        private String channelName;
        @Column(name = "NAME")
        private String name;
        @Column(name = "CONVERTION_TYPE")
        private String conversionType;
        @Column(name = "M_INFO")
        private Double mInfo;
        @Column(name = "B_INFO")
        private Double bInfo;
        @Column(name = "VOLTAGE_DIVIDE")
        private String voltageDivide;
        @Column(name = "SAMPLE_RANGE")
        private String sampleRange;
        @Column(name = "SAMPEL_PERIOD")
        private Integer samplePeriod;
        @Column(name = "STORE_ROW")
        private Boolean storeRow;
        @Column(name = "STORE_CONVERTED")
        private Boolean storeConverted;
        @Column(name = "DEFAULT_GRAPH")
        private String defaultGraph;
        @Column(name = "TITLE")
        private String title;
        @Column(name = "UNITS")
        private String units;
        @Column(name = "RANGE_LOWERBOUND")
        private Integer rangeLowerbound;
        @Column(name = "RANGE_UPPERBOUND")
        private Integer rangeUpperbound;
        @OneToMany(mappedBy = "ioConfiguration", fetch = FetchType.EAGER)
        private List<Alert> alerts;
        @OneToMany(mappedBy = "ioConfiguration", fetch = FetchType.EAGER)
        private List<DataSeriesMeta> dataSeriesMeta;
        @OneToMany(mappedBy = "ioConfiguration", fetch = FetchType.LAZY)
        private List<NodeData> nodeData;
        @Column(name = "CODE")
        private String code;
        @Column(name = "ACTIVE")
        private Boolean active;

      And here is how I insert the rows:

      private void init() {
          ioConfigurationDAO = new IOConfigurationDAO();
          property = new AigatewayProperty();
          for (int i = 1; i <= property.MAX_PORT_NUM; ++i) {
          List<IOConfiguration> list = ioConfigurationDAO.findAllIOConfiguration();

      And this is part of the table on my cqlsh console:

      It is very clear my data has been inserted into the database.

      All services I have written for my DAO, like insert, delete, modify, work perfect, so I suppose there is no problem with the connection between wildfly and my cassandra database.

      But queries don't work as they are expected if I am using HQL.

      For the endpoint I mentioned above, this is the method I am trying to call:

        public List<IOConfiguration> findAllIOConfiguration() {
          Query query = this.getManager().createNativeQuery("select * from \"IO_CONFIGURATION\"");
          // Query query = this.getManager().createQuery("from IOConfiguration");
          return query.getResultList();

      If I use createNativeQuery like the first line, the endpoint will work perfect, and this is the result I get from resteasy:

      But if I use the createQuery like the second line, the endpoint will not work and give me an empty list.

      Here is my persistence.xml for reference:

      <?xml version="1.0"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
          <persistence-unit name="JPAService">
              <!-- Use the Hibernate OGM provider: configuration will be transparent -->
                  <property name="hibernate.transaction.jta.platform" value="JBossAS" />
                  <property name="jboss.as.jpa.providerModule" value="org.hibernate:5.0" />
                  <property name="hibernate.ogm.datastore.provider" value="cassandra_experimental"/>
                  <property name="hibernate.ogm.datastore.host" value=""/>
                  <property name="hibernate.ogm.datastore.database" value="dev"/>

      I don't know what's the reason. It's very strange, can someone explain this to me?