-->
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.  [ 9 posts ] 
Author Message
 Post subject: Two classes mapped to same table confuse bidirectionality
PostPosted: Tue Feb 03, 2004 7:35 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
I have two classes QuoteRequest and CallingListItem mapped to the same table quote_requests. The componenets making up the two classes are different of course but they both have a one-to-many mapping to another class Quote. Now, quote has a many-to-one mapping to QuoteRequest.

when i execute from QuoteRequest I get a luist of quote request objects as expected but when I execute from CallingListItem I get a WrongClassException with the message " Object with id 1234 was not of the specified class quoteRequest"

Is this a bug or are my mappings wrong? Is it ok to have more than one class mapped to the same table or am I doing something that hibernate does not allow?

thanks


Top
 Profile  
 
 Post subject: Mappings
PostPosted: Tue Feb 03, 2004 7:54 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Hi!

Could you provide us with the mapping files involved?

Sincerely,

/F


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 8:07 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
The QuoteRequest mapping is

Code:

<hibernate-mapping>

    <class name="com.lab.model.quote.QuoteRequest" table="quote_requests">
   
        <id name="id">
            <generator class="sequence">
                <param name="sequence">quote_requests_id_seq</param>
            </generator>
        </id>
       
       <many-to-one name="customer" column="cust_id" outer-join="true" not-null="true" update="false"/>
   
         <property name="product" column="product_type" update="false"/>
      <property name="benefit" column="benefit_type" update="false"/>
      <property name="waiver" column="waiver_basis" update="false"/>
        <property name="sumAssured" column="sum_assured" update="false"/>
        <property name="term" update="false"/>
        <property name="rates" update="false"/>
      <property name="indexLinked" type="boolean" column="index_linked" update="false"/>      
      <property name="specialOffer" type="boolean" column="special_offer" update="false"/>
       
        <component name="error" class="com.lab.common.QuoteError">
           <property name="code" column="error_code"/>
           <property name="message" column="error"/>
        </component>

      <many-to-one name="selectedQuote" column="selected_quote_id" class="com.lab.model.quote.Quote" cascade="delete" outer-join="true"/>


    </class>

</hibernate-mapping>



The CallingListItem mapping is

Code:

    <class name="com.lab.model.CallingListItem" table="quote_requests" polymorphism="explicit">

        <id name="id" column="id">
            <generator class="assigned"/>
        </id>
       
        <many-to-one name="customer" class="com.lab.model.customer.CustomerListItem" column="cust_id"/>

          <property name="lastStatusChangeTime" type="timestamp" column="last_status_change_time"/>
        <property name="lastStatusCheckTime" type="timestamp" column="last_status_check_time"/>
       
      <many-to-one name="quote" class="com.lab.model.quote.Quote" column="selected_quote_id"/>
      
    </class>


and the mapping for Quote is

Code:
   <class name="com.lab.model.quote.Quote" table="quotes">
   
       <cache usage="nonstrict-read-write"/>

        <id name="id">
            <generator class="sequence">
                <param name="sequence">quotes_id_seq</param>
            </generator>
        </id>
       
         <many-to-one name="quoteRequest" class="com.lab.model.quote.QuoteRequest" column="request_id" not-null="true" />

        <many-to-one name="provider" column="provider_id"  not-null="true" update="false"/>

        <property name="premium" update="false"/>
        <property name="rates" update="false"/>
        <property name="sumAssured" column="sum_assured" update="false"/>
        <property name="commissionPcRetained" column="commission_pc_retained" update="false"/>
        <property name="realCommission" column="real_commission" update="false"/>
        <property name="approxCommission" column="approx_commission" update="false"/>

        <property name="note" column="notes" update="false"/>
        <property name="error" column="errors" update="false"/>

     
    </class>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 8:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
It is not intended to keep two objects which map to the same database row in the session at the same time.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 8:23 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
If I made CallingListItem inherit from QuoteRequest would this solve the problem? Is there a better way to do this.

thnak you


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 8:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I suppose no, it is just not supported to associate multiple objects refering to the same row with one session, no matter how you map them.


Top
 Profile  
 
 Post subject: I'm far from sure
PostPosted: Tue Feb 03, 2004 8:45 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
I'm a confused newbie myself, but...

From what I can see you have a <many-to-one> mapping from Quote to QuoteRequest AND a <many-to-one> from QuoteRequest to Quote. What do yo mean by that? Shouldn't you map it as a <many-to-many>?
If you stay with the parent-child model I suggest a good look in the Hibernate2 Reference Documentation 2.1.1, especially chapter 6 and 9.
Pages 49-50 might be especially interesting.

Sincerely,

/F


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 9:14 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
The many-to-one from QuoteRequest to Quote because every quote request has one and only one selected quote. The many-to-one from Quote to QuoteRequest is for bidirectionality, we often need to get the quote request object from the selected quote.

I am not sure what a many-to-many would acomplish as I am not dealing with any collections here. In fact the mapping between selectedQuote and QuoteRequest is one-to-one but we had problems implementing it that way back in hibernate 1.2 and we have not had the time try agin using hibernate 2.1.

My problem is that I need to reference a property of the quotes table from my CallingListItem class but I cannot use the Quote class because it references QuoteRequest which mapped to the same table as CallingListItem. Looks like I will have to create another quote-like class that I can use with calling list item.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 1:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It is not possible (well, at least not without a custom persister) to have two objects representing the same row in the session simultaneously. This is not an unreasonable restriction, I think.


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