• Post Reply Bookmark Topic Watch Topic
  • New Topic

createQuery not working but createNativeQuery works  RSS feed

 
nan xiang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guy, I have a very strange problem.



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

   

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:

   

And here is how I insert the rows:

  

And I can see the rows being inserted into my database from cqlsh console.

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:

   

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:

  

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



Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36854
481
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know. The table looks mapped correctly. Have you tried adding the package name in the Hibernate query?

Also, have you tried this hibernate query:
SELECT c FROM IOConfiguration c
 
Dave Tolls
Ranch Hand
Posts: 2652
29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The fact that you're getting an empty list back and not an exception suggests the syntax is correct.
Have you looked in the database?
Is there anything unusual going on in there?

When you print the List in the init() method is that one empty as well?
 
Rob Spoor
Sheriff
Posts: 20968
84
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably unrelated, but why are you injecting an IOConfigurationDAO with @EJB, then creating a completely new instance (which is not an EJB, since you manage it yourself)? And are you creating a new IOConfigurationDAO instance inside the init method of another instance?
 
nan xiang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:I don't know. The table looks mapped correctly. Have you tried adding the package name in the Hibernate query?

Also, have you tried this hibernate query:
SELECT c FROM IOConfiguration c


Hi, Jeanne, I have tried to do that query as well. And it still gives me an empty list.

Thanks!
 
nan xiang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:The fact that you're getting an empty list back and not an exception suggests the syntax is correct.
Have you looked in the database?
Is there anything unusual going on in there?

When you print the List in the init() method is that one empty as well?


Hi, Dave. I am able to see the rows I have inserted using my cqlsh console. And I can the list I print out in the init() method is not empty. So yeah, my guess is that cassandra does not support HQL for this moment?

Thanks!
 
nan xiang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Probably unrelated, but why are you injecting an IOConfigurationDAO with @EJB, then creating a completely new instance (which is not an EJB, since you manage it yourself)? And are you creating a new IOConfigurationDAO instance inside the init method of another instance?


Hi, Rob. Actually my @EJB annotation doesn't work at all, since my @postconstruct and @predestroy annotations doesn't work, so I have to create the DAO manually....I just leave them for this moment and I will try to figure this problem out later on.

Thanks!
 
Dave Tolls
Ranch Hand
Posts: 2652
29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nan xiang wrote:

Hi, Dave. I am able to see the rows I have inserted using my cqlsh console. And I can the list I print out in the init() method is not empty. So yeah, my guess is that cassandra does not support HQL for this moment?

Thanks!


So, when you run that code using the createQuery version in the findAllIOConfiguration method then the init() method successfully prints out the data, but the List returned by the later call in getAllIoConfigurations doesn't print anything out?

If that's not what's going on, then can I suggest putting some (a lot) of logging in all these methods to trace the calls and the data, and print it out here so we can see what is actually happening in the createQuery situation?
 
nan xiang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:
nan xiang wrote:

Hi, Dave. I am able to see the rows I have inserted using my cqlsh console. And I can the list I print out in the init() method is not empty. So yeah, my guess is that cassandra does not support HQL for this moment?

Thanks!


So, when you run that code using the createQuery version in the findAllIOConfiguration method then the init() method successfully prints out the data, but the List returned by the later call in getAllIoConfigurations doesn't print anything out?

If that's not what's going on, then can I suggest putting some (a lot) of logging in all these methods to trace the calls and the data, and print it out here so we can see what is actually happening in the createQuery situation?


Yes, both createQuery and createNativeQuery work perfect when I am running the test locally. But after I deploy the project, only createNativeQuery works, I don't know what is going on here.

Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!