I want to write a join query for joining two tables in Spring Data, using Hibernate.
sql: select * from a join b on a.B_Id=b.id;
My classes are as below:
In class A
, I don't have reference of B
, I have only B_id. Since its a large project I can't change the class definitions. But need to migrate the join queries to Hibernate.
Any way I can do it?
@Entity
@Table(name = "a")
public class A {
@Id
private Integer id;
// ...
private Integer B_Id;
}
@Entity
@Table(name = "b")
public class B {
@Id
private Integer id;
// ...
}
Many to one mapping -> many A
can have the same B
.