Hi every one I have these classe
@Entity
@Table(name = "login", uniqueConstraints={@UniqueConstraint(columnNames={"username_fk"})})
public class Login implements Serializable {
@Id
@Column(name = "id")
@GeneratedValue
private int id;
@Column(name = "password", length = 64)
private String password;
@Column(name = "roles", length = 32)
private String roles;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@OnDelete(action=OnDeleteAction.CASCADE)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@JoinColumn(name = "username_fk", nullable=false)
private Branch branch;
//some getter and sette
and
@Entity
@Table(name = "branch", uniqueConstraints = {@UniqueConstraint(columnNames = {"bname", "branch_fk"})})
public class Branch implements Serializable {
@Id
@GeneratedValue
private int id;
@Column(name = "username", length = 64, nullable=false)
private String userName;
@Column(name = "bname", length = 64)
private String branchName;
@Column(name = "officername", length = 64)
private String officerName;
@Column(name = "studcount")
private int studCount;
@Column(name = "blevel", columnDefinition="int default 0")
private int level;
@Column(name = "officeremail", length = 64)
private String officerEmail;
@Column(name = "confirmed", columnDefinition = "tinyint default 0")
private int confirmed;
@OneToOne(mappedBy = "branch", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@OnDelete(action=OnDeleteAction.CASCADE)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private Login login;
when i use this Query :
executeQuery("select l from Login as l inner join l.branch as b where l.branch.bname = ?", username)
or this:
executeQuery("select b.login from Branch b where b.username = ?", username)
I have get this error:
org.hibernate.QueryException: could not resolve property: bname of: Data.Entity.Branch
but when use this code:
executeQuery("select b.login from Branch b where b.id = ?", username)
it's return correct result
I means this type of HQL just work for Primary key? or my maping have problem? is there any way that I can use other field(except Primary Key) form joinable table?