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: Table x class hierarchy: hibernate updates when inserting..
PostPosted: Thu Jan 04, 2007 11:56 am 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2
Mapping documents:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class discriminator-value="-1" table="transferrecord" name="com.mm.mw..dto.TransferRecordImpl">
<id unsaved-value="0" name="recordNumber" column="id">
<generator class="increment"/>
</id>
<discriminator type="int" column="interfaceType"/>
<property name="creationTimestamp"/>
<property name="status"/>
<property name="dlfSiteRef"/>
<property name="transmissionNumber"/>
<property name="transmissionTimestamp"/>
<property name="interfaceType" column="interfaceType" update="false" insert="false"/>
<subclass name="com.mm.mw..lenternshg.ExpectedReceipt" discriminator-value="2">
<property name="cofcref"/>
<property name="locationRef"/>
<property name="ticket"/>
<property name="quantity"/>
<property name="partNumber"/>
</subclass>
<subclass name="com.mm.mw..lenternshg.ReceiptConfirmation" discriminator-value="1">
<property name="cofcref"/>
<property name="locationRef"/>
<property name="manualInd"/>
<property name="productRef"/>
<property name="receiptRef"/>
<property name="operatorRef"/>
<property name="scanner"/>
<property name="ticket"/>
</subclass>
<subclass name="com.mm.mw.lenternshg.ReplenRequest" discriminator-value="0">
<property name="valid"/>
<property name="manualInd"/>
<property name="operatorRef"/>
<property name="productRef"/>
<property name="locationRef"/>
<property name="scanDate"/>
<property name="scanTime"/>
<property name="scanner"/>
<property name="stockOutInd"/>
</subclass>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
testInsertRecordDAO(com.waersystems.mw.tests.BaseMWTest) Time elapsed: 0.172 sec <<< ERROR!
org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:93)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:79)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:193)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:905)
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:394)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:674)
at com.mm.mw.dao.impl.GenericHibernateDAO.makePersistent(GenericHibernateDAO.java:56)
at com.mm.mw.tests.BaseMWTest.testInsertRecordDAO(BaseMWTest.java:63)

Name and version of the database you are using:

The generated SQL (show_sql=true):
Hibernate: update transferrecord set creationTimestamp=?, status=?, dlfSiteRef=?
, transmissionNumber=?, transmissionTimestamp=? where id=?

hi all,
i have an hibernate app that uses spring..
in my app i have 4 classes, i am using table x class hierarchy with a discriminator.
for some reasons, this code:
Code:
TransferRecordImpl  replRequest = createTransferRecord(replRequest);

        System.err.println("Inserting TransferRecord...");
        System.err.println("RecordDAO != NULL?" + (recordDAO != null));
        recordDAO.makePersistent(replRequest);
        System.err.println("TR inserted.. now trying t


which in turn calls this codE
Code:
getHibernateTemplate().saveOrUpdate(entity);


results in hibernate doing an update instead of an insert... any particular reason why??

thanks in advancea nd regars
marco


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 12:00 pm 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
and apologies to all...
i was doing something wrong in my code while setting the id of the object being persisted....
i used generator class="increment" and i was setting it deliberately..

apologies to all..

regards
marco


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.