Using...
Code:
@Id
@GeneratedValue
private Long id;
I import some stuff using import.sql leaving Hibernate to "auto" its id generation for the entity.
Code:
insert into user (id, version4OptLock, first_name, last_name, email, password, phone_number, mobile_number, last_login) values (2, 0, 'Test1', 'Surname1', 'test1@entermyevents.com', 'password', 'xxx1', 'yyy1', '2012-01-02 01:00:00')
insert into user (id, version4OptLock, first_name, last_name, email, password, phone_number, mobile_number, last_login) values (3, 0, 'Test2', 'Surname2', 'test2@entermyevents.com', 'password', 'xxx2', 'yyy2', '2012-01-03 18:00:00')
insert into user (id, version4OptLock, first_name, last_name, email, password, phone_number, mobile_number, last_login) values (4, 0, 'Test3', 'Surname3', 'test3@entermyevents.com', 'password', xxx3', yyy3', '2012-01-04 23:59:59')
When I try to add a new entity I get a clash as it tries to use a used id (that was used in import.sql).
Code:
16:21:32,353 INFO [com.entermyevents.userManagement.UserCreationController] (http--127.0.0.1-8080-2) Added User [id=2, optlock=0, firstName=asdasd, lastName=asdas, email=dasda@asdasd, password=dasdas, phoneNumber=sdasdasd, mobileNumber=asdasd, lastLogin=Sat Feb 18 16:21:32 NZDT 2012, delegates=null, friends=null, pictures=null, affiliations=null, attachements=null, maintenanceDates=null]
16:21:32,355 INFO [com.entermyevents.userManagement.UserCreationController] (http--127.0.0.1-8080-2) +++CONVERSATION END for conversation:2
16:21:32,358 INFO [stdout] (http--127.0.0.1-8080-2) Hibernate:
16:21:32,358 INFO [stdout] (http--127.0.0.1-8080-2) insert
16:21:32,359 INFO [stdout] (http--127.0.0.1-8080-2) into
16:21:32,359 INFO [stdout] (http--127.0.0.1-8080-2) user
16:21:32,359 INFO [stdout] (http--127.0.0.1-8080-2) (email, first_name, last_login, last_name, creation_date, date_effective_from, date_effective_to, mobile_number, version4OptLock, password, phone_number, pictures_id, id)
16:21:32,361 INFO [stdout] (http--127.0.0.1-8080-2) values
16:21:32,361 INFO [stdout] (http--127.0.0.1-8080-2) (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
16:21:32,363 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http--127.0.0.1-8080-2) SQL Error: 1062, SQLState: 23000
16:21:32,363 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http--127.0.0.1-8080-2) Duplicate entry '2' for key 'PRIMARY'
16:21:32,364 WARN [com.arjuna.ats.arjuna] (http--127.0.0.1-8080-2) ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple< 0:ffffc0a80164:13e2cf68:4f3f15e1:d0, org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization@7e334e4a >: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: Duplicate entry '2' for key 'PRIMARY'
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1361) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1295) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl$CallbackExceptionMapperImpl.mapManagedFlushFailure(AbstractEntityManagerImpl.java:1481) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:109) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:53) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:273)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:93)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:164)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1165)
Id's 1,2,3,4 have already been used when I look in the DB (used up by import.sql).
This used to work in Seam 2.
A hibernate_sequence table is created and next_val is 1 (not to say that its even used in this case).
Environment:
CDI (Weld) on JBoss AS 7.1.0.Final "Thunder".
2xExtra libs : prettyfaces and primefaces.