I have the below query, where two tables are joining on non primary column. The table is joining on one common column.
In entity, I have not provided any joining between User and UserDetails, and I don't want to provide either
SELECT * from User user, UserDetails ud
WHERE user.user_key = :pUserKey // passed in parameter
user.common_key = ud.common_key
User
@Entity
@Table(name = "USER")
@Data
public class User implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "user_key", nullable = false)
@JsonIgnore
private Long userKey;
@Column(name = "common_key ", nullable = false)
@JsonIgnore
private Long commonKey;
}
UserDetails
@Entity
@Table(name = "USER_DETAILS")
@Data
public class UserDetails implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "user_details_key", nullable = false)
@JsonIgnore
private Long userDetailsKey;
@Column(name = "common_key ", nullable = false)
@JsonIgnore
private Long commonKey;
}
How to achieve the same query in JPA specification