-->
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.  [ 4 posts ] 
Author Message
 Post subject: question about one-to-many delete
PostPosted: Wed Oct 15, 2003 5:58 am 
Newbie

Joined: Thu Sep 11, 2003 2:07 am
Posts: 4
There are one to many association between the following class:

Code:
---------------------------------------------------------------------------


      <class
          name="EventLog"
          table="chassis_event_log"
          dynamic-update="false"
          dynamic-insert="false"
        >

        <id
            name="id"
            column="id"
            type="java.lang.String"
            length="32"
            unsaved-value="null"
        >
            <generator class="uuid.hex">
            </generator>
        </id>

        <property
            name="trapTime"
            type="java.util.Date"
            update="true"
            insert="true"
            column="trap_time"
        />

        <many-to-one
            name="chassis"
            class="Chassis"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="serial_number"
            not-null="false"
        />

    </class>

--------------------------------------------------------------------------


    <class
        name="com.threeup.phoenix.persistence.Chassis"
        table="chassis"
        dynamic-update="true"
        dynamic-insert="false"
    >

        <id
            name="serialNumber"
            column="serial_number"
            type="java.lang.String"
            length="32"
        >
            <generator class="assigned">
            </generator>
        </id>

        <set
            name="eventLogs"
            lazy="true"
            inverse="true"
            cascade="none"
            sort="unsorted"
            order-by="trap_time desc"
        >

              <key
                  column="serial_number"
              />

              <one-to-many
                  class="EventLog"
              />
        </set>
    </class>
-----------------------------------------------------------

Now there are some records in EventLog associated with one record in Chassis. when I delete this record in Chassis, I still retain those records in EventLog.

but when I select these records from EventLog then, the following error occurs:

net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists (serialnumber of chassis)......

from what i see, it seems that when hibernate select records from EventLog, it also fetch relevant record from Chassis.

can this fetch be disabled?

Thanks a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2003 8:11 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The outer-join attribute accepts three different values:
* auto (default) Fetch the association using an outerjoin if the associated class has no proxy
* true Always fetch the association using an outerjoin
* false Never fetch the association using an outerjoin


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2003 8:43 pm 
Newbie

Joined: Thu Sep 11, 2003 2:07 am
Posts: 4
Thanks for your reply.
but when I set outer-join to false now, the same problem still exists.
does hibernate have other solutions?

epbernard wrote:
The outer-join attribute accepts three different values:
* auto (default) Fetch the association using an outerjoin if the associated class has no proxy
* true Always fetch the association using an outerjoin
* false Never fetch the association using an outerjoin


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2003 9:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
You don't have a proxy set up for the Chasis class, thus when you load that linked EventLog instance, Hibernate will atempt to load the associated Chasis object. So the only option for "disabling the fetch" would be to map Chasis with a proxy. However, attempting to access the Chasis association from an EventLog instance would still cause that exception.

As a side note, this is not a good O/R setup or even really a good relational setup. All "hard associations" like this should conceivably be backed by DB RI constraints. If if were, the DB would not even let you delete that particular Chasis row as it would cause constraint violations. You could try a "soft reference" where the "relation" is not really an association. In our apps, all our main DB tables contain audit info such as who create a record, when it was created, who last modified it, and when it was last modified. The fields for who created a record and who last modified it are VARCHAR'ed version of the person-id of the user performing those actions. There is no RI constraint setup against these columns and in Hibernate they are mapped as simple Strings. This allows us to freely delete persons at will and the apps can handle missing associations.


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