-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to get the id from persisted objects when using JPA
PostPosted: Thu Feb 28, 2008 7:27 pm 
Newbie

Joined: Thu Feb 28, 2008 6:43 pm
Posts: 1
This may seem a silly question but:

If I have an object similar to below, and use JPA/hib to create the id.

@Entity
public class Item {
@Id @GeneratedValue
private Long id;
private String name;

... getters/setters ...
}

then do:


Item item1 = new Item();
item1.setName("Test Name");
em.persist(item1);

Item item2 = new Item();
item2.setName("Test Name");
em.persist(item2);

Given that it's created OK on the database with 2 new rows on the item table, how can I sync whats in the 2 objects in memory against whats now in the db. i.e. how do I get the generated id's back into the item objects ?

Thanks,


Top
 Profile  
 
 Post subject: Re: How to get the id from persisted objects when using JPA
PostPosted: Thu Feb 28, 2008 7:30 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
They should be in the objects right after persist.



Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.