-->
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: Mapping to one only row in a set
PostPosted: Wed Sep 19, 2012 12:18 pm 
Newbie

Joined: Wed Sep 19, 2012 11:46 am
Posts: 1
I have essentially the following tables:
Person (id, name, ssn)
Customer (id, account_start_date)
Order(id, customer_id, item, order_date)

My hibernate is basically configured as follows:

Code:
<hibernate-mapping package="my.pkg">
<class name="Person" table="person">
          <id name="id" type="long" />
          <property name="name" type="string" />
          <property name="ssn" type="string" />

          <joined-subclass name="Customer" table="customer" >
                <key column="id" />
               <property name="account_start_date" type="timestamp" />
                <set name="orders" table="order" cascade="delete" order-by="order_date desc" >
                       <key column="customer_id" />
                       <one-to-many class="Order" />
                </set>
         </joined-subclass>
   </class>

   <class name="Order" table="order">
          <id name="id" type="long" />
          <property name="curstomer_id" type="long" />
          <property name="item" type="string" />
          <property name="order_date" type="timestamp" />
  </class>


Loading a set of orders every time I get a customer from the database and passing that data around is negatively impacting my performance. I only ever need the most recent order for each customer to be loaded with that customer object. I do need to get all orders at other times, but when dealing with a customer, I only ever need the latest order. Naturally, I can't use a one-to-one mapping since it's not one-to-one. I can't do a join to the joined_subclass. I tried messing with subselects and formulas, but nothing seems to work. How can I configure my XML to load just the latest order instead of the entire set?


Thanks.


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.