-->
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: Mapping with composite keys
PostPosted: Thu Aug 08, 2013 2:19 pm 
Newbie

Joined: Wed Mar 19, 2008 11:19 am
Posts: 15
Location: Orlando
I have 3 entities: OrderHeader, OrderLocationHeader, and OrderDetail

The relationships are as follows:
OrderHeader -> OrderLocationHeader (1:M)
OrderHeader -> OrderDetail (1:M)
OrderLocationHeader -> OrderDetail (1:M).

Each entity uses the following EmbeddedIds:
OrderHeaderId (Integer season, String number)
OrderLocationHeaderId (OrderHeader header, PickupLocation pickupLocation)
OrderDetailId (OrderHeader header, Integer sequence)

PickupLocation is also an Emeddable (Integer exchange, Integer association, Integer packingHouse)

When hibernate tries to join OrderDetail to OrderLocationHeader, this is the SQL that is generated:
Code:
left outer join FRORL orderlocat4_ on
    od1_.locationHeader_OLORD#=orderlocat4_.OLORD# and <- Order#
    od1_.locationHeader_OLSEAS=orderlocat4_.OLSEAS and <- Season
    od1_.locationHeader_OLASC#=orderlocat4_.OLASC# and <- Association
    od1_.locationHeader_OLEXC#=orderlocat4_.OLEXC# and <- Exchange
    od1_.locationHeader_OLPKH#=orderlocat4_.OLPKH# <- Packing House

If all the "locationHeader_OL" pieces were "OD", I would be good. I've tried the various JPA Override annotations among other things to no avail.

Please advise. Thanks!


Top
 Profile  
 
 Post subject: Re: Mapping with composite keys
PostPosted: Sun Aug 11, 2013 10:48 pm 
Newbie

Joined: Wed Mar 19, 2008 11:19 am
Posts: 15
Location: Orlando
I managed to solve this on my own. By making OrderLocationHeader the parent of OrderDetail (OrderDetailId (OrderLocationHeader locationHeader, Integer sequence)) and by using a mix of @AttributeOverrides and @AssociationOverrides, I was able to get the mappings to work properly. Then, I was also able to create a direct link between Header and Detail. On the Detail, I just had to declare the @JoinColumns as not insertable/updatable (since they will be set via the Id)


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.