連接查詢我已經創建了兩個豆類用戶和虛擬域中具有多對多的關係如何編寫休眠
@Entity
@Table(name = "tblUser")
public class User implements Serializable {
private Long id;
private String username;
private Set<VirtualDomain> virtualdomainset;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name = "username", length = 50, nullable = false)
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@ManyToMany(targetEntity = VirtualDomain.class, cascade = {CascadeType.PERSIST},fetch=FetchType.EAGER)
@JoinTable(name = "tblUserDomainRel", joinColumns = @JoinColumn(name = "userid"), inverseJoinColumns = @JoinColumn(name = "domainid"))
public Set<VirtualDomain> getVirtualdomainset() {
return virtualdomainset;
}
public void setVirtualdomainset(Set<VirtualDomain> virtualdomainset) {
this.virtualdomainset = virtualdomainset;
}
}
@Entity
@Table(name = "tblVirtualDomain")
public class VirtualDomain {
private Long id;
private String domainname;
private Set<User> userset;
@Id
@JoinColumn(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name = "domain_name")
public String getDomainname() {
return domainname;
}
public void setDomainname(String domainname) {
this.domainname = domainname;
}
@ManyToMany(cascade = {CascadeType.ALL},fetch=FetchType.EAGER, mappedBy = "virtualdomainset", targetEntity = User.class)
public Set<User> getUserset() {
return userset;
}
public void setUserset(Set<User> userset) {
this.userset = userset;
}
}
如何讓用戶喜歡通過Hibernate與特定的域用戶名的數據。
布萊克。請幫助我 當我使用這個查詢它給我的錯誤java.lang.NoSuchMethodError:org.hibernate.hql.antlr.HqlBaseParser.recover(Lantlr/RecognitionException; Lantlr/collections/impl/BitSet;)V – Jugal 2009-06-04 13:22:18
我'已編輯查詢,查詢中不應該有任何用戶。 – 2009-06-04 13:33:50
你編輯的查詢看起來不錯,但我只想從用戶的用戶名字段,所以當我添加選擇子句,如選擇u.username,它給了我錯誤org.hibernate.QueryException:查詢指定的聯接提取,但獲取的關聯的所有者不是出現在選擇列表 – Jugal 2009-06-04 13:53:06