[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Getting generated ID by sequence

stupar.aleksandar do-not-reply at jboss.com
Mon Mar 5 05:39:01 EST 2007


I'm writing entity for person and this is the part of the class.

@Entity
  | @SequenceGenerator(name = "tsperson_sequence", sequenceName = "SEQ_TSPERSON_ID")
  | public class Tsperson implements Serializable {
  |     @Id
  |     @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="tsperson_sequence")
  |     @Column(name="TSPERSON_ID", nullable = false)
  |     private Long tspersonId;

What i'm trying to do is to get an Id after I flush person data 
into database.

	Tsperson person = new Tsperson();
  |         person.setFirstName("kill");
  |         person.setLastName("em");
  |         person.setUserName("all");
  | 
  |         em.persist(person);       
  |         System.out.println(person.getTspersonId());        
  |         em.flush();
  |         System.out.println(person.getTspersonId());   

But all I get is old
stohastic Long value generated by container. 

Output is something like this:
3150
3150
and primary key in database is 60.

Could someone tell my is this normal and how can I 
get value generated from database sequence 
into Person's memory.

Thnx in front.

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

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4025009



More information about the jboss-user mailing list