-->
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: Attempt to Delete causes Update with Null on non null field
PostPosted: Thu Oct 02, 2003 1:20 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Okay I'm sure I'm doing it wrong, but I can't figure out what the right way is. Everything I have tried (short of having no object associations) is causing update statements instead of deletes.

I have the following mappings:
Code:
   <!-- Product Colour -->
   <class name="com.fgl.ina.stylecreation.coloursize.ProductColour" table="product_colour">
      <id name="colourID" column="colour_ID" unsaved-value="none" type="integer">
         <column name="colour_ID" not-null="true" unique="false"/>
         <generator class="assigned"/>
      </id>
      <many-to-one name="parentProduct" column="ina_prod_id" class="com.fgl.ina.stylecreation.Product"
            not-null="true" unique="false"/>
   </class>

   <!-- Product -->
   <class name="com.fgl.ina.stylecreation.Product" table="product_style">
      <id name="productID" column="ina_prod_id" type="integer" unsaved-value="0">
         <generator class="net.sf.hibernate.id.IdentityGenerator"/>
      </id>

      <set name="colours" cascade="all-delete-orphan" inverse="false" lazy="true" order-by="colour_ID">
         <key column="ina_prod_id"/>
         <one-to-many class="com.fgl.ina.stylecreation.coloursize.ProductColour"/>
      </set>
   </class>


I also tried having the child class like this:
Code:
   <!-- Product Colour -->
   <class name="com.fgl.ina.stylecreation.coloursize.ProductColour" table="product_colour">
      <composite-id unsaved-value="none">
         <key-many-to-one name="parentProduct" column="ina_prod_id" class="com.fgl.ina.stylecreation.Product"/>
         <key-property    name="colourID"      column="colour_ID"   type="integer"/>
      </composite-id>
   </class>


and like this:
Code:
   <!-- Product Colour -->
   <class name="com.fgl.ina.stylecreation.coloursize.ProductColour" table="product_colour">
      <composite-id unsaved-value="none">
         <key-property name="productID" column="ina_prod_id" type="integer"/>
         <key-property name="colourID"  column="colour_ID"   type="integer"/>
      </composite-id>
   </class>


I've tried changing the unsaved-value to "any" which didn't seem to have an affect.
When the child class was mapped as composite-id I had Serializable, equals(), and hashCode() as required.
I've tried explicitly calling delete on the instances I want to delete, I've tried letting the cascade="all-delete-orphan" on the parent do it's thing and the same error happens each way:

My debug log looks like this:
Code:
Hibernate: update product_colour set ina_prod_id=null where ina_prod_id=? and colour_ID=?
10:50:43,542  WARN JDBCExceptionReporter:38 - SQL Error: 515, SQLState: HY000
10:50:43,552 ERROR JDBCExceptionReporter:46 - [Macromedia][SQLServer JDBC Driver][SQLServer]Cannot insert the value NULL into column 'ina_prod_id', table 'INA.dbo.product_colour'; column does not allow nulls. UPDATE fails.
10:50:43,552  WARN JDBCExceptionReporter:38 - SQL Error: 515, SQLState: HY000
10:50:43,552 ERROR JDBCExceptionReporter:46 - [Macromedia][SQLServer JDBC Driver][SQLServer]Cannot insert the value NULL into column 'ina_prod_id', table 'INA.dbo.product_colour'; column does not allow nulls. UPDATE fails.
10:50:43,552 ERROR JDBCExceptionReporter:75 - Could not execute JDBC batch update macromedia.jdbc.base.BaseBatchUpdateException: [Macromedia][SQLServer JDBC Driver][SQLServer]Cannot insert the value NULL into column 'ina_prod_id', table 'INA.dbo.product_colour'; column does not allow nulls. UPDATE fails.
        at macromedia.jdbc.sqlserver.SQLServerImplStatement.getBatchRowsAffectedCount(Unknown Source)
        at macromedia.jdbc.base.BasePreparedStatement.executeBatch(Unknown Source)
        at jrun.sql.JRunStatement.executeBatch(JRunStatement.java:421)
        at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:50)
        at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:116)
        at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2324)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2278)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2219)
        at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
...


If I load a List of the child objects manually instead of loading the parent product and getting them that way I seem to be able to delete them just fine, but if I load the parent object and try to delete them or just remove them from the collection and update the parent I get the Update behaviour trying to set a not-null column to null instead of a delete being issued.

What am I doing wrong? What is the correct way to handle this? My ProductColour object is really just a cross reference being used for convenience as an object in a specific scenario.


Top
 Profile  
 
 Post subject: grrr...
PostPosted: Thu Oct 02, 2003 1:35 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Okay, when I switched to having the child hold a reference to its parent I forgot to change the parent mapping to have inverse="true" and now having done that the problem is gone.

However, I would still like to know why when treating it not as a parent child bidirectional relationship (specifically when I was loading the children more like value objects) it didn't work even to delete them explicitly?


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.