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)
|