• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to refer one table in second many times?

 
Balaji Kadam
Ranch Hand
Posts: 31
Hibernate Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

i have a scenario my first table contains master data with different codes
like
A Table

and second table having first table reference twice
like
B Table


How to write relation for this scenario annotation based.

Thank You

 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just reference A twice and use @JoinColumn to give the foreign key.

@Entity
public class B {
...

@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn("name="A1")
private A a1;


@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn("name="A2")
private A a2;

}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic