-->
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: No UPDATE for extra attr in many-to-many table by Hibernate?
PostPosted: Wed Aug 02, 2006 11:57 pm 
Newbie

Joined: Thu Jul 06, 2006 8:38 am
Posts: 14
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hi,

I'm following the example of CategorizedItem in CaveatEmptor to add an attribute to a many-to-many relationship (in my case the attribute is "comment", which is the comment the users will attach to a relationship between a Vendor and a VendorType).

It works beautifully for the most part... except when I want to update comment for an existing combination of Vendor and VendorType. I enabled debug for org.hibernate, but it doesn't seem to generate any UPDATE statement for the comment column in the many-to-many table.

What did I do wrong? Here's all the info.

Thanks in advance,
Ray

Hibernate version:
3.1.3

Mapping documents:
Vendor.hbm.xml (the relevant portion):
Code:
      <set name="vendorAndVendorTypes"
            cascade="all-delete-orphan"
            inverse="true"
            outer-join="false"
            lazy="false">
         <key foreign-key="GME_FK_VVT_VENDOR_ID">
            <column name="VENDOR_ID" not-null="true"/>
         </key>
         <one-to-many class="com.barcap.gcs.gmevents.model.reference.RelVendorAndVendorType"/>
      </set>


RelVendorAndVendorType.hbm.xml:
Code:
   <composite-id name="id" class="RelVendorAndVendorType$Id" unsaved-value="any">
        <key-property name="vendorId"
                      access="field"
                      column="VENDOR_ID"/>

        <key-property name="vendorTypeId"
                      access="field"
                      column="VENDORTYPE_ID"/>
   </composite-id>

    <many-to-one    name="vendor"
                    column="VENDOR_ID"
                    not-null="true"
                    access="field"
                    insert="false"
                    update="false"
                    lazy="false"/>

    <many-to-one    name="vendorType"
                    column="VENDORTYPE_ID"
                    not-null="true"
                    access="field"
                    insert="false"
                    update="false"
                    lazy="false"/>
                   
   <property name="comment" column="COMMENTS" type="string" />


Code between sessionFactory.openSession() and session.close():
Code:
// load persistentVendor...

           Set<RelVendorAndVendorType> detachedVendorAndVendorTypes = formVendor.getVendorAndVendorTypes();
           if(detachedVendorAndVendorTypes != null) {
              persistentVendor.getVendorAndVendorTypes().retainAll(detachedVendorAndVendorTypes);
              for(RelVendorAndVendorType vv : persistentVendor.getVendorAndVendorTypes()) {
                 for(RelVendorAndVendorType dvv : detachedVendorAndVendorTypes) {
                    if(vv.equals(dvv)) {
                       vv.setComment(dvv.getComment());
                    }
                 }
              }
              persistentVendor.getVendorAndVendorTypes().addAll(detachedVendorAndVendorTypes);
           }

           persistentVendor = (Vendor)this.service.saveOrUpdate( persistentVendor );




Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle 9.2

The generated SQL (show_sql=true):
No update is generated, and there should be...

Debug level Hibernate log excerpt:
Code:
2006-08-03 11:39:30,005 DEBUG [org.hibernate.engine.Cascade] - cascade ACTION_SAVE_UPDATE for collection: com.barcap.gcs
.gmevents.model.Vendor.vendorAndVendorTypes
2006-08-03 11:39:30,005 DEBUG [org.hibernate.engine.CascadingAction] - cascading to saveOrUpdate: com.barcap.gcs.gmevent
s.model.reference.RelVendorAndVendorType
2006-08-03 11:39:30,005 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - persistent instance of: com.barcap.g
cs.gmevents.model.reference.RelVendorAndVendorType
2006-08-03 11:39:30,021 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] - ignoring persistent instance
2006-08-03 11:39:30,021 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] - object already associated wit
h session: [com.barcap.gcs.gmevents.model.reference.RelVendorAndVendorType#component[vendorId,vendorTypeId]{vendorId=983
55, vendorTypeId=10141}]
2006-08-03 11:39:30,021 DEBUG [org.hibernate.engine.CascadingAction] - cascading to saveOrUpdate: com.barcap.gcs.gmevent
s.model.reference.RelVendorAndVendorType
2006-08-03 11:39:30,052 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - persistent instance of: com.barcap.g
cs.gmevents.model.reference.RelVendorAndVendorType
2006-08-03 11:39:30,052 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] - ignoring persistent instance
2006-08-03 11:39:30,052 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] - object already associated wit
h session: [com.barcap.gcs.gmevents.model.reference.RelVendorAndVendorType#component[vendorId,vendorTypeId]{vendorId=983
55, vendorTypeId=10144}]
2006-08-03 11:39:30,052 DEBUG [org.hibernate.engine.CascadingAction] - cascading to saveOrUpdate: com.barcap.gcs.gmevent
s.model.reference.RelVendorAndVendorType
2006-08-03 11:39:30,052 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - persistent instance of: com.barcap.g
cs.gmevents.model.reference.RelVendorAndVendorType
2006-08-03 11:39:30,067 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] - ignoring persistent instance
2006-08-03 11:39:30,067 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] - object already associated wit
h session: [com.barcap.gcs.gmevents.model.reference.RelVendorAndVendorType#component[vendorId,vendorTypeId]{vendorId=983
55, vendorTypeId=10142}]
2006-08-03 11:39:30,067 DEBUG [org.hibernate.engine.Cascade] - done cascade ACTION_SAVE_UPDATE for collection: com.barca
p.gcs.gmevents.model.Vendor.vendorAndVendorTypes


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.