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