How do I join two tables in hibernate and Spring. below is my suto java code and I need to do a join on objectA where the name field is equal to the name field in objectB but I am going to be searching on ObjectA ID field but I need returned. ObjectA ID, ObjectA Name, ObjectA Regin, ObjectB Address.
//
// CLASS OBJECT A
//
@Entity
@Table(name = "tableA")
public class ObjectA {
@Id
@Column(name = "id")
private String id;
@Column(name = "name")
private String name;
@Column(name = "region")
private String region;
}
//
// CLASS OBJECT B
//
@Entity
@Table(name = "tableB")
public class ObjectB {
@Id
@Column(name = "id")
private String id;
@Column(name = "name")
private String name;
@Column(name = "address")
private String address;
}
can someone please tell me how to do this within the java code.
Add this to your A class:
So that when you retrieve for A, you’ll get inside corresponding B by name.