-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with Delete NULL with composite-element Map
PostPosted: Tue Mar 22, 2005 2:20 pm 
Beginner
Beginner

Joined: Tue Sep 21, 2004 4:04 pm
Posts: 25
Location: Oldsmar, FL
Hi All,

My problem is, when I modify an element in a composite-element Map Hibernate is issuing a DELETE with the composite-id fields set to NULL.
The delete is of course failing and throwing an exception.

If you look at the Log and Stack trace below, you see that it's correctly
updating the parent, then updating the child then incorrectly issuing a delete with the key fields set to null.

How do I dix this?
TIA


Hibernate version: 2.1.8

Mapping documents:

RoutingTemplateSet.hbm.xml
Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class
        name="com.paperclick.common.beans.RoutingTemplateSet"
        table="utbRoutingTemplateSets"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="templateSetId"
            type="java.lang.Long"
        >
            <generator class="native">
            </generator>
        </id>

        <version
            name="version"
            type="int"
            column="version"
            access="property"
            unsaved-value="undefined"
        />

        <property
            name="templateSetKey"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="templateSetKey"
            length="20"
            not-null="true"
            unique="true"
        />

        <property
            name="description"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="description"
            length="500"
            not-null="false"
        />

        <property
            name="lastUpdated"
            type="timestamp"
            update="true"
            insert="true"
            access="property"
            column="lastUpdated"
            not-null="true"
        />

        <property
            name="active"
            type="boolean"
            update="true"
            insert="true"
            access="property"
            column="active"
            not-null="true"
        />

        <map
            name="templates"
            table="utbRoutingTemplates"
            lazy="false"
            sort="unsorted"
            inverse="false"
            cascade="all-delete-orphan"
        >

              <key
                  column="templateSetId"
                  foreign-key="FK_ROUTINGTEMPLATES_ROUTINGTEMPLATESETS"
              >
              </key>

              <index
                  column="cmdType"
                  type="string"
                  length="20"
              />

              <composite-element
                  class="com.paperclick.common.beans.RoutingTemplate"
              >

        <property
            name="urlTemplate"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="urlTemplate"
            length="200"
            not-null="true"
        />

        <property
            name="action"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="action"
            length="20"
            not-null="true"
        />

        <property
            name="description"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="description"
            length="500"
            not-null="false"
        />

              </composite-element>

        </map>

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-RoutingTemplateSet.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>



RoutingTemplate.hbm.xml
Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class
        name="com.paperclick.common.beans.RoutingTemplate"
        table="utbRoutingTemplates"
        dynamic-update="false"
        dynamic-insert="false"
    >
      <composite-id>
           <key-many-to-one
               name="templateSet"
               class="com.paperclick.common.beans.RoutingTemplateSet"
               access="property"
               foreign-key="FK_ROUTINGTEMPLATES_ROUTINGTEMPLATESETS"
               column="templateSetId"
           />
         <key-property
               name="cmdType"
               type="java.lang.String"
               access="property"
               column="cmdType"
               length="20"
         />
      </composite-id>

        <property
            name="urlTemplate"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="urlTemplate"
            length="200"
            not-null="true"
        />

        <property
            name="action"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="action"
            length="20"
            not-null="true"
        />

        <property
            name="description"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="description"
            length="500"
            not-null="false"
        />

    </class>

</hibernate-mapping>



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

I get a RoutingTemplateSet then modify a RoutingTemplate in the "templates" Map.

Code:
tx = session.beginTransaction();
RoutingTemplateSet rts = (RoutingTemplateSet) session.createCriteria(
                RoutingTemplateSet.class).add(
                Expression.eq("templateSetKey", "SET1")).uniqueResult();

((RoutingTemplate) rts.getTemplates().get("GET")).setAction("PROXY");
tx.commit();


Full stack trace of any exception that occurs:
    Caused by: net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
    at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
    at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.java:583)
    at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:29)
    at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
    at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2396)
    at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2260)
    at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
    at com.neom.jnmtools.db.hibernate.HibernateUtil.commitTransaction(HibernateUtil.java:254)
    ... 20 more



Name and version of the database you are using: SQL Server 2000

Debug level Hibernate log excerpt w/ generated SQL (show_sql=true) :

    Hibernate: select this.templateSetId as template1_0_, this.version as version0_, this.templateSetKey as template3_0_, this.description as descript4_0_, this.lastUpdated as lastUpda5_0_, this.active as active0_ from dbo.utbRoutingTemplateSets this where this.templateSetKey=?
    12:23:12,996 DEBUG StringType:46 - binding 'SET1' to parameter: 1
    12:23:13,012 DEBUG LongType:68 - returning '29' as column: template1_0_
    12:23:13,012 DEBUG HibernateUtil:253 - Committing database transaction of this thread.
    Hibernate: update dbo.utbRoutingTemplateSets set version=?, templateSetKey=?, description=?, lastUpdated=?, active=? where templateSetId=? and version=?
    12:23:13,027 DEBUG IntegerType:46 - binding '1' to parameter: 1
    12:23:13,027 DEBUG StringType:46 - binding 'SET1' to parameter: 2
    12:23:13,027 DEBUG StringType:46 - binding 'description for Set1' to parameter: 3
    12:23:13,027 DEBUG TimestampType:46 - binding '2005-03-22 12:23:12' to parameter: 4
    12:23:13,027 DEBUG BooleanType:46 - binding 'true' to parameter: 5
    12:23:13,027 DEBUG LongType:46 - binding '29' to parameter: 6
    12:23:13,027 DEBUG IntegerType:46 - binding '0' to parameter: 7
    Hibernate: update dbo.utbRoutingTemplates set urlTemplate=?, action=?, description=? where templateSetId=? and cmdType=?
    12:23:13,027 DEBUG LongType:46 - binding '29' to parameter: 4
    12:23:13,043 DEBUG StringType:46 - binding 'http://get.test.com/link.jsp?SET=set1&TYPE=PCLINK&CMD=GET&CODE=[CODE]' to parameter: 1
    12:23:13,043 DEBUG StringType:46 - binding 'PROXY' to parameter: 2
    12:23:13,043 DEBUG StringType:41 - binding null to parameter: 3
    12:23:13,043 DEBUG StringType:46 - binding 'GET' to parameter: 5
    Hibernate: delete from dbo.utbRoutingTemplates where templateSetId=? and cmdType=?
    12:23:13,058 DEBUG LongType:41 - binding null to parameter: 1
    12:23:13,058 DEBUG StringType:41 - binding null to parameter: 2
    12:23:13,058 ERROR SessionImpl:2399 - Could not synchronize database state with session
    12:23:13,058 DEBUG HibernateUtil:276 - Tyring to rollback database transaction of this thread.
    12:23:13,074 DEBUG HibernateUtil:212 - Closing Session of this thread.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 22, 2005 3:44 pm 
Beginner
Beginner

Joined: Tue Sep 21, 2004 4:04 pm
Posts: 25
Location: Oldsmar, FL
The log above was not quite right as I hadn't opened a new session so some items were coming from the cache. Here a correct log.
[code]
13:49:01,564 DEBUG HibernateUtil:179 - Opening new Session for this thread.
Hibernate: select this.templateSetId as template1_0_, this.version as version0_, this.templateSetKey as template3_0_, this.description as descript4_0_, this.lastUpdated as lastUpda5_0_, this.active as active0_ from dbo.utbRoutingTemplateSets this where this.templateSetKey=?
13:49:01,580 DEBUG StringType:46 - binding 'SET1' to parameter: 1
13:49:01,596 DEBUG LongType:68 - returning '34' as column: template1_0_
13:49:01,596 DEBUG IntegerType:68 - returning '0' as column: version0_
13:49:01,596 DEBUG StringType:68 - returning 'SET1' as column: template3_0_
13:49:01,596 DEBUG StringType:68 - returning 'description for Set1' as column: descript4_0_
13:49:01,596 DEBUG TimestampType:68 - returning '2005-03-22 13:49:01' as column: lastUpda5_0_
13:49:01,611 DEBUG BooleanType:68 - returning 'true' as column: active0_
Hibernate: select templates0_.templateSetId as template1___, templates0_.urlTemplate as urlTempl3___, templates0_.action as action__, templates0_.description as descript5___, templates0_.cmdType as cmdType__ from dbo.utbRoutingTemplates templates0_ where templates0_.templateSetId=?
13:49:01,611 DEBUG LongType:46 - binding '34' to parameter: 1
13:49:01,611 DEBUG LongType:68 - returning '34' as column: template1___
13:49:01,611 DEBUG StringType:68 - returning 'http://desc.test.com/link.jsp?SET=set1&TYPE=PCLINK&CMD=DESC&CODE=[CODE]' as column: urlTempl3___
13:49:01,611 DEBUG StringType:68 - returning 'PROXY' as column: action__
13:49:01,611 DEBUG StringType:68 - returning 'Description for DESC' as column: descript5___
13:49:01,611 DEBUG StringType:68 - returning 'DESC' as column: cmdType__
13:49:01,611 DEBUG LongType:68 - returning '34' as column: template1___
13:49:01,611 DEBUG StringType:68 - returning 'http://get.test.com/link.jsp?SET=set1&TYPE=PCLINK&CMD=GET&CODE=[CODE]' as column: urlTempl3___
13:49:01,611 DEBUG StringType:68 - returning 'REDIRECT' as column: action__
13:49:01,627 DEBUG StringType:64 - returning null as column: descript5___
13:49:01,627 DEBUG StringType:68 - returning 'GET' as column: cmdType__
13:49:01,627 DEBUG HibernateUtil:253 - Committing database transaction of this thread.
Hibernate: update dbo.utbRoutingTemplateSets set version=?, templateSetKey=?, description=?, lastUpdated=?, active=? where templateSetId=? and version=?
13:49:01,643 DEBUG IntegerType:46 - binding '1' to parameter: 1
13:49:01,658 DEBUG StringType:46 - binding 'SET1' to parameter: 2
13:49:01,658 DEBUG StringType:46 - binding 'description for Set1' to parameter: 3
13:49:01,658 DEBUG TimestampType:46 - binding '2005-03-22 13:49:01' to parameter: 4
13:49:01,658 DEBUG BooleanType:46 - binding 'true' to parameter: 5
13:49:01,658 DEBUG LongType:46 - binding '34' to parameter: 6
13:49:01,658 DEBUG IntegerType:46 - binding '0' to parameter: 7
Hibernate: update dbo.utbRoutingTemplates set urlTemplate=?, action=?, description=? where templateSetId=? and cmdType=?
13:49:01,658 DEBUG LongType:46 - binding '34' to parameter: 4
13:49:01,658 DEBUG StringType:46 - binding 'http://get.test.com/link.jsp?SET=set1&TYPE=PCLINK&CMD=GET&CODE=[code]' to parameter: 1
13:49:01,674 DEBUG StringType:46 - binding 'PROXY' to parameter: 2
13:49:01,674 DEBUG StringType:41 - binding null to parameter: 3
13:49:01,674 DEBUG StringType:46 - binding 'GET' to parameter: 5
Hibernate: delete from dbo.utbRoutingTemplates where templateSetId=? and cmdType=?
13:49:01,674 DEBUG LongType:41 - binding null to parameter: 1
13:49:01,674 DEBUG StringType:41 - binding null to parameter: 2
13:49:01,690 ERROR SessionImpl:2400 - Could not synchronize database state with session
13:49:01,705 DEBUG HibernateUtil:276 - Tyring to rollback database transaction of this thread.
13:49:01,705 DEBUG HibernateUtil:212 - Closing Session of this thread.

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 22, 2005 4:12 pm 
Beginner
Beginner

Joined: Tue Sep 21, 2004 4:04 pm
Posts: 25
Location: Oldsmar, FL
Sorry, I think the DELETE NULL is a red-herring, I debugged into Hibernate code and think I understand the issue a little better, but still don't know how to solve the real problem.

I believe the DELETE NULL was occuring because the Map element class RoutingTemplate composite-id fields (cmdType and templateSet) are not being set, and thus contained nulls.

How do I get the composite-id fields in the Map element to be set?
I tried adding them to the composite-element but get a MappingException for repeat columns (I'm guessing it's because they are already in there as the index and the key.

Code:
net.sf.hibernate.MappingException: Repeated column in mapping for collection: com.paperclick.common.beans.RoutingTemplateSet.templates column: templateSetId


The next thing I tried was to remove the composite-id fields (cmdType and templateSet) from the Map element class since they are not used. This failed because the Map element mapping RoutingTemplate.hbm.xml refers to them in the composite-id

Code:
      <composite-id>
           <key-many-to-one
               name="templateSet"
               class="com.paperclick.common.beans.RoutingTemplateSet"
               access="property"
               foreign-key="FK_ROUTINGTEMPLATES_ROUTINGTEMPLATESETS"
               column="templateSetId"
           />
         <key-property
               name="cmdType"
               type="java.lang.String"
               access="property"
               column="cmdType"
               length="20"
         />
      </composite-id>


I'm lost now, I don't what to try next... please help.
TIA


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.