I am trying to get JoinTable annotation to work using hibernate. My entities look like:
Code:
@Entity
@Table("users")
public class User {
@Id
@GeneratedValue
private int id;
@ManyToOne
@JoinTable(name = "joinTable",
joinColumns = @JoinColumn(name = "userId", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "roleId", referencedColumnName = "id")
)
private Role role;
}
Code:
@Entity
@Table("roles")
public class Role {
@Id
@GeneratedValue
private int id;
}
If I issue a query like:
Code:
select u from User u where u.role.id = :roleid
The generated query is:
Code:
select
user0_.id as id1_0_,
user0_.roleid as role1_2_
from
users user0_
where
user0_.roleid=?
This query was previously working when user and role had different property names for their "id" (userId and roleId respectively)