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: auto-generated primary key causing commit to fail?
PostPosted: Thu Aug 24, 2006 10:00 am 
Newbie

Joined: Thu Aug 24, 2006 9:06 am
Posts: 4
Location: Maryland
I'm having a problem getting hibernate to commit a new object to the database when the database is set up to generate the primary key (the ID field) upon insertion. The column rowguid in the Antennas table is of type uniqueidentifier. I've mapped that to a string for lack of a better option.

It looks like the ID is being generated properly, but then the commit fails because of a synchronization problem. I've no idea how to troubleshoot this.

This is a legacy database, so I cannot alter it in any way to remove the error.

--Trudy


Hibernate version: Hibernate 3.0.5

Mapping documents:
<class name="com.integ.raidrs.model.Antenna"
table="Antennas" mutable="true" polymorphism="implicit"
dynamic-update="false" dynamic-insert="false" batch-size="1"
select-before-update="false" optimistic-lock="version">

<id name="ID" column="rowguid" type="java.lang.String" >
<generator class="guid"/>
</id>


<property name="antennaName" type="java.lang.String"
column="AntennaName" length="100" not-null="false" unique="false"
update="true" insert="true" />
<property name="xpoleant" type="java.lang.String"
column="XPoleAnt" />
<property name="polarization" type="java.lang.String"
column="Polarization" length="100" not-null="false" unique="false"
update="true" insert="true" />
<property name="antennaId" type="java.lang.String"
column="AntennaId" length="100" not-null="false" unique="false"
update="true" insert="true" />
</class>

Code between sessionFactory.openSession() and session.close():
Unfortunately, I can't see it. It's wrapped in some proprietary code that I'm using.

Full stack trace of any exception that occurs:

24 Aug 2006 13:41:25,630 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.transaction.JDBCTransaction - begin
24 Aug 2006 13:41:25,630 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.jdbc.ConnectionManager - opening JDBC connection
24 Aug 2006 13:41:25,630 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.connection.DriverManagerConnectionProvider - total checked-out connections: 0
24 Aug 2006 13:41:25,630 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.connection.DriverManagerConnectionProvider - using pooled JDBC connection, pool size: 0
24 Aug 2006 13:41:25,630 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.transaction.JDBCTransaction - current autocommit status: false
24 Aug 2006 13:41:25,630 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener - saving transient instance
24 Aug 2006 13:41:25,630 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
24 Aug 2006 13:41:25,630 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.SQL - select newid()
24 Aug 2006 13:41:25,630 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
24 Aug 2006 13:41:25,645 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.id.GUIDGenerator - GUID identifier generated: 6e8fa35f-2c41-4e17-8454-800d92ffdc80
24 Aug 2006 13:41:25,645 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
24 Aug 2006 13:41:25,645 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
24 Aug 2006 13:41:25,645 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.event.def.AbstractSaveEventListener - generated identifier: 6e8fa35f-2c41-4e17-8454-800d92ffdc80, using strategy: org.hibernate.id.GUIDGenerator
24 Aug 2006 13:41:25,645 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.event.def.AbstractSaveEventListener - saving [model.Antenna#6e8fa35f-2c41-4e17-8454-800d92ffdc80]
24 Aug 2006 13:41:25,645 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.transaction.JDBCTransaction - commit
24 Aug 2006 13:41:25,645 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.impl.SessionImpl - automatically flushing session
24 Aug 2006 13:41:25,645 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - flushing session
24 Aug 2006 13:41:25,645 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - processing flush-time cascades
24 Aug 2006 13:41:25,661 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - dirty checking collections
24 Aug 2006 13:41:25,661 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushing entities and processing referenced collections
24 Aug 2006 13:41:25,661 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Processing unreferenced collections
24 Aug 2006 13:41:25,661 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Scheduling collection removes/(re)creates/updates
24 Aug 2006 13:41:25,661 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
24 Aug 2006 13:41:25,661 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
24 Aug 2006 13:41:25,661 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.pretty.Printer - listing entities:
24 Aug 2006 13:41:25,661 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.pretty.Printer - model.Antenna{polarization=unknown, xpoleant=unknown, antennaId=test, antennaName=testname, ID=6e8fa35f-2c41-4e17-8454-800d92ffdc80}
24 Aug 2006 13:41:25,661 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - executing flush
24 Aug 2006 13:41:25,661 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.persister.entity.BasicEntityPersister - Inserting entity: [model.Antenna#6e8fa35f-2c41-4e17-8454-800d92ffdc80]
24 Aug 2006 13:41:25,661 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
24 Aug 2006 13:41:25,661 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.SQL - insert into Antennas (AntennaName, XPoleAnt, Polarization, AntennaId, rowguid) values (?, ?, ?, ?, ?)
24 Aug 2006 13:41:25,661 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
24 Aug 2006 13:41:25,692 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.persister.entity.BasicEntityPersister - Dehydrating entity: [model.Antenna#6e8fa35f-2c41-4e17-8454-800d92ffdc80]
24 Aug 2006 13:41:25,692 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.type.StringType - binding 'testname' to parameter: 1
24 Aug 2006 13:41:25,692 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.type.StringType - binding 'unknown' to parameter: 2
24 Aug 2006 13:41:25,692 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.type.StringType - binding 'unknown' to parameter: 3
24 Aug 2006 13:41:25,692 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.type.StringType - binding 'test' to parameter: 4
24 Aug 2006 13:41:25,692 [t:service.kbs.MonicsDataHandlerPlugin] DEBUG org.hibernate.type.StringType - binding '6e8fa35f-2c41-4e17-8454-800d92ffdc80' to parameter: 5
24 Aug 2006 13:41:25,692 [t:service.kbs.MonicsDataHandlerPlugin] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.HibernateException: Unexpected row count: 0 expected: 1

at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:32)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1853)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2200)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at ...

Name and version of the database you are using:
SQLServer 2000


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 24, 2006 2:45 pm 
Newbie

Joined: Thu Aug 24, 2006 9:06 am
Posts: 4
Location: Maryland
I figured it out!

There is a trigger on this table. The trigger gets executed before the insert happens. When I run my insert statement from the SQL prompt, the output looks like this:

0 row(s) affected.

1 row(s) affected.


So, hibernate was getting that first 0 and throwing an exception. If I disable the trigger, the insert via hibernate works fabulously.

So now I have to figure out how to tell hibernate that there's a trigger on this table and to ignore it's return value.

--Trudy


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.