-->
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.  [ 1 post ] 
Author Message
 Post subject: problem with SPID as unique id fortwo paralell sessions
PostPosted: Mon Oct 02, 2006 5:18 pm 
Newbie

Joined: Mon Oct 02, 2006 5:00 pm
Posts: 1
2.1.8

Hi,
I'am a newbie on using Hibernate and really need some help. I have struggled with a problem for 2 days without finding any solution.

The problem is that may application sometimes set up two session to a "sybase" database and create a ConnectionLock where the "spid" is unique primary key. The problem is that the second session get the same "spid" as the first one. And excepeption is thrown. Any idea what's wrong or is is it not a good idea to use "spid" as unique id ?


Code;

HibernateUtil.setOutputDebug(true);
session = HibernateUtil.currentSession();
HibernateUtil.setOutputDebug(false);

connectionLock = (ConnectionLock) session.createSQLQuery(
"select @@spid {cl.connectionLockId}", "cl",
ConnectionLock.class).uniqueResult();

log.debug(" ConnectionLockId (or should we say the spid) : " + connectionLock.getConnectionLockId());
session.evict(connectionLock);
Transaction tx = session.beginTransaction();
session.save(connectionLock);
tx.commit();



Exception:

006-10-02 14:34:03,431 DEBUG [CommJobManagerImpl ] - ConnectionLockId (or should we say the spid) : 49
2006-10-02 14:34:03,431 WARN [JDBCExceptionReporter ] - SQL Error: 2601, SQLState: 23W01
2006-10-02 14:34:03,431 ERROR [JDBCExceptionReporter ] - ASA Error -193: Primary key for table 'ConnectionLock' is not unique
2006-10-02 14:34:03,431 ERROR [SessionImpl ] - Could not synchronize database state with session
2006-10-02 14:34:03,447 ERROR [CommJobManagerImpl ] - Error creating HibernateSession
net.sf.hibernate.exception.ConstraintViolationException: could not insert: [com.tomra.nxc.persistance.hibernate.ConnectionLock#49]
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:62)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at net.sf.hibernate.persister.AbstractEntityPersister.convert(AbstractEntityPersister.java:1331)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:472)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:436)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:37)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2449)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2435)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.