This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes get generated key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "get generated key" Watch "get generated key" New topic
Author

get generated key

riccardo alfrilli
Greenhorn

Joined: Mar 03, 2008
Posts: 16
Hi again!
The EntityManager.persist(EntityBean) method doesn't return the generated Id value by the Database...how can i obtain it?

public void create(Tbcustomer tbcustomer) {
em.persist(tbcustomer);
}

I'll try to implements a query or use annotations like @GeneratedValue...
Somebody can help me?
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
It sets the value (or values) in the object you passed it.



Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
riccardo alfrilli
Greenhorn

Joined: Mar 03, 2008
Posts: 16
Tnx for reply!unfortuntely i have an exception,here is my code:


Maybe the @GeneratedValue annotation is wrong(I try also @GeneratedValue(strategy=TABLE),@GeneratedValue(strategy=IDENTITY))
riccardo alfrilli
Greenhorn

Joined: Mar 03, 2008
Posts: 16
Ok,now it's work...I have to set the id(that was an Integer) with initial value of null,not 0!
 
 
subject: get generated key