• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate return a empty object

 
Fabio Falci Rodrigues
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

Is there a good reason to hibernate return a empty object for a query (get by id)?
The id is null and the lists are empty.

Thanks!
entity-sem-id.PNG
[Thumbnail for entity-sem-id.PNG]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean you used the get() method of session. But in order to call get you have to pass in an id, which Hibernate sets in the proxy object, but does not go to the database to load the other data. the load() method does go to the database. so load() can return null if the record doesn't exist, and get can throw an exception if it doesn't exist. But the exception is not thrown in the load() call, it will be thrown when you try to access a property besides id from the resulting object.

Hope that helps clear things a bit for you

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic