I have three tables, Member
, Address
and Mem_Addr
.
Member
and Address
entities are mapped / connected by Mem_Addr
table. Many to Many.
I have the following entities for Member
and Address
:
@Entity
@Table (name="Member")
public class Member{
@Id //....
private Integer mem_id;
@OneToOne
@JoinTable (name = "Mem_Addr",
joinColumns = @JoinColumn(name = "addr_id"),
inverseJoinColumns = @JoinColumn(name = "mem_id"))
Set<Address> addresses = new HashSet<Address>;
...
}
Mem_Addr
table (It has not associated entity).
addr_id // (PK) Sequence
mem_id // (FK to mem_id in Member table)
....
....
Address
entity.
@Entity
@Table(name="Address")
public class Address {
private String addr_id; // Foreign Key to addr_id in Mem_addr table
private String address1;
...
}
I do not have ID in the Address
table/entity. (Please don't ask me about the design. Its not changeable right now.)
So when I load Members, I want to load all address locations for that member.
What is the solution?
Edit: More info...
Basically some Member
s will have a new entry in Mem_Addr
table. For each entry in Mem_addr
table there will be an entry in Address
table.
To get the address of a member, I need to refer Mem_Addr. Mem_Addr has addr_id
as primary and Address has addr_id
as foreign key.