This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes I am getting null value for particular column, while loading the object. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "I am getting null value for particular column, while loading the object." Watch "I am getting null value for particular column, while loading the object." New topic
Author

I am getting null value for particular column, while loading the object.

Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 204
I have an entity bean which is made using Hibernate annotation.




so, whenever I save the particular POJO, it's get saved into the table properly. Here id is Autogenerated value and dElementId is Primary key.
now, once I save and then try to load the particular entity from DB, i get value of id as null but do get proper value of dElementId.

Now, my question is why I am getting null value for id colum though it has proper value in table. I am commiting the transaction as well as flushing the transaction too, but did not help. Remember as soon as I save the object, I am trying to retrieve the object, because I need id value.



Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

Your id field is autogenerated but you have @Id annotation on the dElementId field??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 204

This is because, DAElementID is primary key in database..hence...ID is is sequence generated value....
Please let me know opinion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I am getting null value for particular column, while loading the object.
 
Similar Threads
table not mapped error when compiling entity bean
org.hibernate.PropertyValueException: not-null property references a null or transient value:
IllegalArgumentException: cannot remove/save a detached entity
Hibernate One To Many Not Null
hibernate question - left outer join (best practices)