-->
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.  [ 3 posts ] 
Author Message
 Post subject: Multiple one-to-many using single join table
PostPosted: Thu May 04, 2006 12:13 pm 
Beginner
Beginner

Joined: Sat Apr 15, 2006 12:49 pm
Posts: 20
Location: austria
hib 3.2.0.cr1 / ann 3.1.0.Beta10

Hi,

I'm wondering if the following is possible with hibernate annotations:

I have the following annotated classes:

Code:
@Entity
public class Customer() {
   private Long cusomerId;
   ...
   private Set<Address> shippingAddresses = new HashSet<Address>();
   private Set<Address> billingAddresses = new HashSet<Address>();
   
   // unidirectional
   @OneToMany(targetEntity=Address.class, cascade = CascadeType.ALL)
   @JoinTable(name = "tblBusinessContact2BillingAddresses", joinColumns = {
   @JoinColumn(name = "businessContact_id") }, inverseJoinColumns =    @JoinColumn(name = "billingAddress_id"))
   public Set<Address> getBillingAddresses() {
      return billingAddresses;
   }

   // unidirectional
   @OneToMany(targetEntity=Address.class, cascade = CascadeType.ALL)
   @JoinTable(name = "tblBusinessContact2ShippingAddresses", joinColumns = {
   @JoinColumn(name = "businessContact_id") }, inverseJoinColumns =    @JoinColumn(name = "shippingAddress_id"))
   public Set<Address> getShippingAddresses() {
      return shippingAddresses;
   }
}

@Entity
public class Address() {
   private Long addressId;
   ....
}


My intetion now would be to map both the shipping and the billing-address sets on one single *:* join table having a similar structure like the following:
Code:
create table Customer2Addresses(customerId bigint not null, addressId bigint not null, type varchar(50), primary key (customerId, addressId, type));


whereas I would like to use the 'type' column as discriminator distinguishing between shipping and billing addresses.

Could anyone please tell me if something like this is possible?

Thanks,

john


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 2:45 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no it's not

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 3:00 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
well you can do it but you need to map an intermediate entity

_________________
Emmanuel


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