-->
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: @GeneratedValue auto-increment problem
PostPosted: Wed Nov 26, 2008 12:19 pm 
Newbie

Joined: Wed Nov 26, 2008 10:58 am
Posts: 2
Using the Java Persistence with Hibernate book "Hello World" example from chapter 2 as a guide, I created an Employee class with an Id field that is annotated as follows:

@Id @GeneratedValue
@Column(name = "EMPLOYEE_ID")
private Long _id;

From main, I create an Employee instance and call the method below to insert it to the MySql DB. It is inserted with EMPLOYEE_ID= 1. Then I create another Employee instance and call the same method below. This time it appears to update the first record with the field values of the new Employee, rather than insert a new record with EMPLOYEE_ID= 2, which is what I expected. So only one record is in the DB, even thought I called the method below twice. It appears that it is not auto incrementing the ID. Can anyone help?



public boolean insertEmployee(Employee inEmployee)
{
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("employee");

EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();

em.persist(inEmployee);

tx.commit();

// Shutting down the application service
em.close();

return true;
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2008 3:11 pm 
Newbie

Joined: Wed Nov 26, 2008 10:58 am
Posts: 2
Please disregard - I resolved the issue


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.