-->
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: One-based list indexes, how?
PostPosted: Thu Sep 16, 2004 9:40 am 
Newbie

Joined: Thu Sep 16, 2004 9:09 am
Posts: 3
Hi all,

I am using Hibernate to access data in a legacy database.
I have a class (Order) that has many line items. My Hibernate mapping of the line items in the Order class is as follows...
<list name="lineItems" lazy="true" cascade="all">
<key column="customer_order_id"/>
<index column="line_number" />
<one-to-many class="com.rpc.core.customer.model.CustomerOrderLineItem"/>
</list>

However, the line_number column used above is one-based, that is, int he database line items are numbered from 1 to n. However, the Order.getLineItems() method needs to return a zero-based list of line items. That is, the oth item in the List returned from Order.getLineItems() should be the line item with a line number of 1.

I tried to modify the above mapping by adding a type to the index that would transform the 1-based DB indexes to 0-based object indexes as follows...

<list name="lineItems" lazy="true" cascade="all">
<key column="customer_order_id"/>
<index column="line_number" type="net.sf.hibernate.eclipse.datatype.OneBasedIndexUserType" />
<one-to-many class="com.rpc.core.customer.model.CustomerOrderLineItem"/>
</list>


However, Hibernate seems to ignore the type if the index. To test this I set breakponts in the OneBasedIndexUserType class and they were never hit.

So, does anybody know how I can successfully map these line items with Hibernate?

TIA,
ted stockwell


Top
 Profile  
 
 Post subject: Try this.
PostPosted: Tue Mar 01, 2005 12:06 pm 
Newbie

Joined: Wed Nov 05, 2003 9:10 am
Posts: 6
I'm sure that the OP has found some workaround by now. If you manage to stumble across this thread with the same problem, however, I tried the following, and it worked much as I expected.


Code:
<bag name="lineItems" lazy="true" cascade="all" order-by="line_number">
  <key column="customer_order_id"/>
  <one-to-many class="com.rpc.core.customer.model.CustomerOrderLineItem"/>
</bag>


For my application, this works, since the elements that go in the bag are largely static. For the OP's application, keeping order-items in a bag is not the most efficient storage solution.


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.