-->
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.  [ 4 posts ] 
Author Message
 Post subject: EJB3 - How get generated ID after persist()?
PostPosted: Fri Nov 04, 2005 5:14 am 
Newbie

Joined: Fri Nov 04, 2005 5:10 am
Posts: 3
Hi to all...i have an entity bean (UserEBean) and its "Id" is defined like:

@Id(generate=GeneratorType.SEQUENCE, generator="USERS_SEQ")
@javax.persistence.SequenceGenerator(
name="USERS_SEQ",
sequenceName="users_user_id_seq"
)
@Column(name="user_id", nullable=false)
public Long getUserId() {
return userId;
}


Respective session bean has the method:

public void save(UserEBean bean)
{
// TODO Auto-generated method stub
manager.persist(bean);
}


In an other class i set properties in an UserEBean variable and then i call:

userDAO.save(my_userbean);

How can i get the entity's ID which i just persisted?

Thanks to all!
Paolo.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 5:47 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
my_userbean.getId()

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 6:13 am 
Newbie

Joined: Fri Nov 04, 2005 5:10 am
Posts: 3
my_userbean.getId() doesn't work...i get a null value... :(


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 10:35 am 
Newbie

Joined: Fri Nov 04, 2005 5:10 am
Posts: 3
I found the solution!!!
In my session bean i wrote:


public void save(UserEBean bean)
{
// TODO Auto-generated method stub
manager.persist(bean);
}


...but the method must be return an "UserBEan" object...the returned object must be the object that i passed to save() method....


public UserEBean save(UserEBean bean)
{

manager.persist(bean);

return bean;

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.