Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

object.getId() returns null. (JPA)

EdChouaffeJul 20 2012 — edited Jul 20 2012
Hi guys.

I'm using a Class call Boom that is persisted using JPA. I have also written DAO classes that implement database access methods for that class.
I also use transactions (EJB stateless session beans) to access the dao classes.

One problem that I have been facing is that findById(Long id) returns a not null object, but when I call getId() on that object, it returns null. A little precision, I have declared the id with nullable = false within the Boom class.
The most surprising is the fact that, when I call toString() on the return object, the ID is set while at the same time object.getId() returns null.

For example:

Boom object = this.getBoomDAO().findById(anId);
System.out.println(object.getId());
System.out.println(object.toString());


Output:
null
1023

Best regards.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 17 2012
Added on Jul 20 2012
11 comments
3,588 views