-->
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: Legacy parent/child with composite id
PostPosted: Mon Jul 02, 2007 5:47 am 
Beginner
Beginner

Joined: Thu Aug 19, 2004 5:36 am
Posts: 30
Location: Italy
I have to create objects and mapping to a parent/child structure for a legacy database.

In short, I have a parent object "Invoice" with a child "InvoiceRow". Both have composite id's.

INVOICE(year, number, customer)

INVOICEROW(year, number, row, item)

(underlined fields are business key members).

Hibernate version: 3.2.4.sp1

I've tried with the following mappings, but with no success in insert and delete of childs.

Mapping documents:

Code:
<class name="Invoice" table="invoice">
   
    <composite-id name="invoiceId" class="org.test.InvoiceId">
      <key-property name="year" type="short"/>
      <key-property name="number" type="integer"/>
    </composite-id>
      
    <property name="customer" type="string" length="10"/>
      
    <set name="rowSet" cascade="all-delete-orphan" inverse="true"
        sort="org.test.RowComparator">
      <key>
        <column name="year"/>
        <column name="number"/>
      </key>
      <one-to-many class="InvoiceRow"/>
    </set>
            
</class>


Code:
<class name="InvoiceRow" table="invoicerow">
   
    <composite-id>
      <key-many-to-one
          name="invoice"
          class="Invoice">
        <column name="year"/>
        <column name="number"/>
      </key-many-to-one>
      <key-property name="row" type="integer"/>
    </composite-id>

    <property name="item" type="string" length="10"/>
            
</class>


InvoiceId is the class of the Invoice identifier and is defined in a quite obvious way.

row field is assigned manually.

One of the problems is that equals and hashCode of child are defined to be a function of the index field of the child (row).
I know this is an error, but there is no other set of fields to correctly define these methods.

Any suggestion?


Last edited by delta on Tue Jul 03, 2007 8:12 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 03, 2007 8:04 am 
Beginner
Beginner

Joined: Thu Aug 19, 2004 5:36 am
Posts: 30
Location: Italy
At the last I'm able to load Invoice, fetch InvoiceRow(s), insert new InvoiceRow.
But the problem is that I cannot delete InvoiceRows.

The problem is that values in row field must range from 1 to <number_of_InvoiceRows> with no holes in the sequence.

So, if I have these records of InvoiceRows (year, number row item):

2007, 100, 1, aaa
2007, 100, 2, bbb
2007, 100, 3, ccc
2007, 100, 4, ddd
2007, 100, 5, eee

and I want to delete the third record, I can obtain, with Hibernate:

2007, 100, 1, aaa
2007, 100, 2, bbb
2007, 100, 4, ddd (but should be 3)
2007, 100, 5, eee (but should be 4)

Hibernate don't allow me to persist changes to 'row' value. For VALID and OBVIOUS reasons.

Please don't tell me that this is bad: I already know that.

I need a workaround.

Thank you very much


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.