• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate returns list of nulls although executed SQL returns values

 
              
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a problem with hibernate. I'm using hibernate as an ORMapper and I want to execute an actually rather simple hql query:



This hql query is then converted into a sql query which looks something like this:



When I execute the sql on the oracle database using the Oracle SQL Developer I get 17 rows returned. However, when I execute the hql query (using the list method of a Query I get a list of 17 elements that are all null. Although the number of elements is correct, not a single one of the elements is actually loaded.

This is the way I create and execute my query:



The result I'm getting after executing query.list();


I've recently upgrade from hibernate 3.2 to 4.3.5. Before the upgrade everything worked fine. After the upgrade I get this error. Also this error seems to only occur with one entity (all ~200 other entities work correctly).

Does anyone know what might be the problem here?
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Markus, welcome to CodeRanch!

Have you tried enabling hibernate TRACE level logs? They usually have enough info to understand what's going on with issues like these?
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, can you post the Entity class "Foo" that you use in that HQL?
 
              
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jaikiran, thanks for your answer. I will try to set the log level to trace. (why didn't I think of this myself..?) The code of Foo will probably not help because its some selfmade solution (that works for all ~200 other entities). However I'll check that agian.
 
              
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I set the log level to TRACE I'll see the following

2014-07-10 13:38:56,422 <main> [TRACE] org.hibernate.loader.Loader.processResultSet(Loader.java:946) - Processing result set
2014-07-10 13:38:56,423 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 0
2014-07-10 13:38:56,424 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,425 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 1
2014-07-10 13:38:56,426 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,427 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 2
2014-07-10 13:38:56,429 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,430 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 3
2014-07-10 13:38:56,431 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,432 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 4
2014-07-10 13:38:56,433 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,434 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 5
2014-07-10 13:38:56,436 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,437 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 6
2014-07-10 13:38:56,438 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,439 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 7
2014-07-10 13:38:56,441 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,442 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 8
2014-07-10 13:38:56,443 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,444 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 9
2014-07-10 13:38:56,445 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,450 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 10
2014-07-10 13:38:56,452 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,453 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 11
2014-07-10 13:38:56,455 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,456 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 12
2014-07-10 13:38:56,457 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,458 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 13
2014-07-10 13:38:56,459 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,461 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 14
2014-07-10 13:38:56,462 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,463 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 15
2014-07-10 13:38:56,464 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,465 <main> [DEBUG] org.hibernate.loader.Loader.processResultSet(Loader.java:951) - Result set row: 16
2014-07-10 13:38:56,467 <main> [DEBUG] org.hibernate.loader.Loader.getRow(Loader.java:1485) - Result row: null
2014-07-10 13:38:56,468 <main> [TRACE] org.hibernate.loader.Loader.processResultSet(Loader.java:970) - Done processing result set (17 rows)


Any ideas why the result row is always null?
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect it has to do with the "id" column(s) of that specific entity. The lines reporting that log message is here https://github.com/hibernate/hibernate-orm/blob/4.3.5.Final/hibernate-core/src/main/java/org/hibernate/loader/Loader.java#L1485 and that too seems to indicate something along those lines. So posting the entity class or even reviewing it yourself might give you a hint on what's wrong or what's different from other entities.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your Entity mappings, also what happens if you execute the query without the order by clauses?
 
              
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the problem. Thanks Jaikiran Pai for the guidance!!

It was actually a mapping/logic/database error. The primary key consisted of two columns (according to the entity class) and one of these columns was nullable. However a primary key can never be nullable. Therefore hibernate always returned null.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic