-->
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: Unexpected update to child with cascade level set to "n
PostPosted: Mon Mar 20, 2006 5:22 pm 
Beginner
Beginner

Joined: Tue Aug 23, 2005 3:52 pm
Posts: 26
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Whenenver I try to update a parent object with empty child collection i get the following exception because hibenrate attempts to cascade changes and update children. I have collection set up as a 'cascade="none"' and i have no problem inserting parent object with empty collection of children. Does anyone have any clue what is wrong with my set up.

Thanks.
Leonid

3.05

Code:
hibernate-mapping>
    <class name="com.bfm.order.Placement" table="placement">
         <id name="placementNum" column="placement_num" >
            <generator class="identity" />      
         </id>
         <version name="version" column="version" />
         
         <list name="fills"  lazy="true" cascade="none" fetch="subselect" collection-type="com.bfm.db.hibernate.usertype.BRMapEncodableList">
            <key column="placementNum"/>
            <index column="fillNum"/>
            <one-to-many class="com.bfm.order.Fill"/>
         </list>
         
         
      </class>
</hibernate-mapping>

<hibernate-mapping>
    <class name="com.bfm.order.Fill" table="fill">
         <id name="fillNum" column="fill_num">
            <generator class="identity" />      
         </id>
         <version name="version" column="version" />
         <property name="placementNum" column="placement_num" />
         
      </class>
      



Executed code
Code:

public List update(final List placementList) throws DAOException {
      try {
         return (List) getHibernateTemplate().execute(new HibernateCallback() {
            
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
               if(placementList == null || placementList.size() < 1){
                  //can't persist null or empty list
                  return placementList;
               }
               
               for(Iterator it = placementList.iterator(); it.hasNext();){               
                  session.update(it.next());                  
               }               
               return placementList;
            }
         });
      } catch(DataAccessException e) {
         log.error("Failed to persist placement");
         throw new DAOException("Failed to persist placement", e);
      }
      
   }


DEBUG 14:37:12,839 org.hibernate.SQL - update orderdb.dbo.placement set version=?, ord_num=?, cusip=?, ticker=?, open_date=?, currency=?, settle_date=?, tran_type=?, ord_type=?, quantity=?, limit_type=?, limit_value=?, stop_type=?, stop_value=?, broker_code=?, desk_id=?, venue_code=?, comment=?, broker_reason=?, commission_rate=?, commission_rate_type=?, time_in_force=?, exec_inst=?, exp_date=?, effective_time=?, handling_inst=?, min_quantity=?, max_floor=?, peg_difference=?, discretion_offset=?, discretion_inst=?, modified_by=?, modified_time=? where placement_num=? and version=?
DEBUG 14:37:13,210 org.hibernate.SQL - update orderdb.dbo.fill set placement_num=null, fill_num=null where placement_num=?
WARN 14:37:13,731 org.hibernate.util.JDBCExceptionReporter - SQL Error: 7744, SQLState: ZZZZZ
ERROR 14:37:13,731 org.hibernate.util.JDBCExceptionReporter - Illegal attempt to update identity field 'fill_num'.

WARN 14:37:13,731 org.hibernate.util.JDBCExceptionReporter - SQL Error: 233, SQLState: 23000
ERROR 14:37:13,731 org.hibernate.util.JDBCExceptionReporter - The column fill_num in table orderdb.dbo.fill does not allow null values.

WARN 14:37:13,731 org.hibernate.util.JDBCExceptionReporter - SQL Error: 233, SQLState: 23000
ERROR 14:37:13,731 org.hibernate.util.JDBCExceptionReporter - The column placement_num in table orderdb.dbo.fill does not allow null values.

ERROR 14:37:13,731 org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: could not delete collection: [com.bfm.order.Placement.fills#99]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:860)
at org.hibernate.action.CollectionRemoveAction.execute(CollectionRemoveAction.java:22)
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:138)
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 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.orm.hibernate3.HibernateTemplate$CloseSuppressingInvocationHandler.invoke(HibernateTemplate.java:1133)
at $Proxy4.flush(Unknown Source)
at com.bfm.order.server.dao.hibernate.PlacementDAOImpl$4.doInHibernate(PlacementDAOImpl.java:185)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:358)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:331)
at com.bfm.order.server.dao.hibernate.PlacementDAOImpl.update(PlacementDAOImpl.java:172)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:292)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy1.update(Unknown Source)
at com.bfm.CheckOrderLock.testCreatAndUpldatePlacement(CheckOrderLock.java:104)
at com.bfm.CheckOrderLock.main(CheckOrderLock.java:59)
Caused by: com.sybase.jdbc3.jdbc.SybSQLException: Illegal attempt to update identity field 'fill_num'.

at com.sybase.jdbc3.tds.Tds.processEed(Tds.java:3069)
at com.sybase.jdbc3.tds.Tds.nextResult(Tds.java:2373)
at com.sybase.jdbc3.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
at com.sybase.jdbc3.jdbc.SybStatement.nextResult(SybStatement.java:220)
at com.sybase.jdbc3.jdbc.SybStatement.nextResult(SybStatement.java:203)
at com.sybase.jdbc3.jdbc.SybStatement.updateLoop(SybStatement.java:1811)
at com.sybase.jdbc3.jdbc.SybStatement.executeUpdate(SybStatement.java:1794)
at com.sybase.jdbc3.jdbc.SybPreparedStatement.executeUpdate(SybPreparedStatement.java:116)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at org.hibernate.persister.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:850)
... 30 more


Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


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.