0

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.

user3696933
  • 69
  • 1
  • 5
  • Refer https://www.javatpoint.com/jpa-many-to-one-mapping – ASP Nov 05 '19 at 05:16
  • Have already mentioned in the question, that I don't have the whole B object in the A class, to declare the mapping, as opposed in the example mentioned in the link you gave. – user3696933 Nov 05 '19 at 05:41
  • 1
    Refer to the link mentioned below: https://stackoverflow.com/questions/19977130/joining-two-table-entities-in-spring-data-jpa – marco525 Nov 05 '19 at 06:25

0 Answers0