-->
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: import.sql seems not to update sequence (CDI/Weld)
PostPosted: Fri Feb 17, 2012 11:28 pm 
Newbie

Joined: Tue Feb 07, 2012 12:12 pm
Posts: 7
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.


Top
 Profile  
 
 Post subject: Re: import.sql seems not to update sequence (CDI/Weld)
PostPosted: Sat Feb 25, 2012 1:07 am 
Newbie

Joined: Tue Feb 07, 2012 12:12 pm
Posts: 7
This problem only happens with create-drop when the table hibernate_sequence has a value of 1

Once I have loaded data (through a previous create-drop and import.sql) and set the hibernate.hbm2ddl.auto to update then hiberanate wanders about the DB and sets hibernate_sequence to the correct value of 7.

So the fix may be for Hibernate to do the same wander about the DB on create-drop AFTER it does the import.sql in a create-drop.

???


Top
 Profile  
 
 Post subject: Re: import.sql seems not to update sequence (CDI/Weld)
PostPosted: Sat Feb 25, 2012 4:10 am 
Newbie

Joined: Tue Feb 07, 2012 12:12 pm
Posts: 7
Sorry red-herring.


Top
 Profile  
 
 Post subject: Re: import.sql seems not to update sequence (CDI/Weld)
PostPosted: Sat Feb 25, 2012 4:43 am 
Newbie

Joined: Tue Feb 07, 2012 12:12 pm
Posts: 7
Can I set a param to start the indexing higher? I cant see an option but its a workround?

e.g.
<property name="hibernate.offset_id" value="1000" />

<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" /> <!-- create-drop update -->
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<!-- These are the default for JBoss EJB3, but not for HEM: -->
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup" />
<property name="jboss.entity.manager.factory.jndi.name"
value="java:/essistantEntityManagerFactories" />
</properties>


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.