2
嗨每一個我有這些CLASSEHQL問題
@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
和
@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;
當我使用這個查詢:
executeQuery("select l from Login as l inner join l.branch as b where l.branch.bname = ?", username)
或本:
executeQuery("select b.login from Branch b where b.username = ?", username)
我得到這個錯誤:
org.hibernate.QueryException: could not resolve property: bname of: Data.Entity.Branch
但是當使用此代碼:
executeQuery("select b.login from Branch b where b.id = ?", username)
it's return correct result
我意味着這種類型的HQL的只是主鍵的工作?或我的地圖有問題? 有什麼辦法可以使用其他字段(主鍵除外)形式可連接的表嗎?
Tanx Man:P 我是新手在Hibernate中並不知道很多東西 Tanx爲你的快速回答 – Am1rr3zA 2009-07-19 13:45:44