[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jboss-user
Subject:    [jboss-user] [JBoss Seam] - EntityHome.persist - Getting the
From:       dustismo <do-not-reply () jboss ! com>
Date:       2007-02-28 21:49:49
Message-ID: 18207709.1172699389745.JavaMail.jboss () colo-br-02 ! atl ! jboss ! com
[Download RAW message or body]

Hi,

I have an entity home class and I need to get the generated id (database generated) \
of the persisted object after calling persist (I would have thought this would be \
automatic?)..  It always comes back as 0.

Here is my entityHome class:


  | @Name("userHome")
  | public class UserHome extends EntityHome<User> {	
  | 	@In
  | 	private EntityManager entityManager;
  | 	
  | 	public void setUserId(Integer id) {
  | 		setId(id);
  | 	}
  | 
  | 	public Integer getUserId() {
  | 		return (Integer) getId();
  | 	}
  | 	
  | 	@Override
  | 	protected User createInstance() {
  | 		User u = new User();
  | 		return u;
  | 	}
  | 	
  | 	@Override
  | 	public String persist() {
  | 		
  | 		String retval = super.persist();
  | 		User u = this.getInstance();
  | 		System.out.println("Persisted user: " + u.getName() + " id: " +
  | 				u.getId() + " this.id: " + this.getId());
  | 		return retval;
  | 	}
  | }

And the entity:


  | @Entity
  | @Name("user")
  | @Scope(SESSION)
  | @Table(name = "User")
  | public class User implements java.io.Serializable {
  | 
  | 	// Fields    
  | 	private int id;
  | 
  | 	private String name;
  | 
  | 	private String password;
  | 
  | 	// Constructors
  | 
  | 	/** default constructor */
  | 	public User() {
  | 	}
  | 
  | 	// Property accessors
  | 	@Id
  | 	@Column(name = "id", unique = true, nullable = false)
  | 	@NotNull
  | 	public int getId() {
  | 		return this.id;
  | 	}
  | 
  | 	public void setId(int id) {
  | 		this.id = id;
  | 	}
  | 
  | 	@Column(name = "name", nullable = false, length = 64)
  | 	@NotNull
  | 	@Length(min = 3, max = 64)
  | 	public String getName() {
  | 		return this.name;
  | 	}
  | 
  | 	public void setName(String name) {
  | 		this.name = name;
  | 	}
  | 
  | 	@Column(name = "password", nullable = false, length = 16)
  | 	@NotNull
  | 	@Length(min = 4, max = 16)
  | 	public String getPassword() {
  | 		return this.password;
  | 	}
  | 
  | 	public void setPassword(String password) {
  | 		this.password = password;
  | 	}
  | }

Many thanks,
Dustin

View the original post : \
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4023985#4023985

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4023985
 _______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic