我有这个实体,它映射用户和工作组之间的关系
package it.prisma.dal.dao.entities.accounting;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "UserAccount_has_Workgroup")
public class UserAccountHasWorkgroup implements java.io.Serializable {
private static final long serialVersionUID = 6537213525312531347L;
private UserAccountHasWorkgroupId id;
private UserAccount userAccountByUserAccountId;
private WorkgroupPrivilege workgroupPrivilege;
private UserAccount userAccountByApprovedByUserAccountId;
private Workgroup workgroup;
private boolean approved;
public UserAccountHasWorkgroup() {
}
public UserAccountHasWorkgroup(UserAccountHasWorkgroupId id,
UserAccount userAccountByUserAccountId,
UserAccount userAccountByApprovedByUserAccountId,
Workgroup workgroup, boolean approved) {
this.id = id;
this.userAccountByUserAccountId = userAccountByUserAccountId;
this.userAccountByApprovedByUserAccountId = userAccountByApprovedByUserAccountId;
this.workgroup = workgroup;
this.approved = approved;
}
public UserAccountHasWorkgroup(UserAccountHasWorkgroupId id,
UserAccount userAccountByUserAccountId,
WorkgroupPrivilege workgroupPrivilege,
UserAccount userAccountByApprovedByUserAccountId,
Workgroup workgroup, boolean approved) {
this.id = id;
this.userAccountByUserAccountId = userAccountByUserAccountId;
this.workgroupPrivilege = workgroupPrivilege;
this.userAccountByApprovedByUserAccountId = userAccountByApprovedByUserAccountId;
this.workgroup = workgroup;
this.approved = approved;
}
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "userAccountId", column = @Column(name = "userAccountID", nullable = false)),
@AttributeOverride(name = "workgroupId", column = @Column(name = "workgroupID", nullable = false)) })
public UserAccountHasWorkgroupId getId() {
return this.id;
}
public void setId(UserAccountHasWorkgroupId id) {
this.id = id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "userAccountID", nullable = false, insertable = false, updatable = false)
public UserAccount getUserAccountByUserAccountId() {
return this.userAccountByUserAccountId;
}
public void setUserAccountByUserAccountId(
UserAccount userAccountByUserAccountId) {
this.userAccountByUserAccountId = userAccountByUserAccountId;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "workgroupPrivilegeID")
public WorkgroupPrivilege getWorkgroupPrivilege() {
return this.workgroupPrivilege;
}
public void setWorkgroupPrivilege(WorkgroupPrivilege workgroupPrivilege) {
this.workgroupPrivilege = workgroupPrivilege;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "approvedBy_userAccountID", nullable = false)
public UserAccount getUserAccountByApprovedByUserAccountId() {
return this.userAccountByApprovedByUserAccountId;
}
public void setUserAccountByApprovedByUserAccountId(
UserAccount userAccountByApprovedByUserAccountId) {
this.userAccountByApprovedByUserAccountId = userAccountByApprovedByUserAccountId;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "workgroupID", nullable = false, insertable = false, updatable = false)
public Workgroup getWorkgroup() {
return this.workgroup;
}
public void setWorkgroup(Workgroup workgroup) {
this.workgroup = workgroup;
}
@Column(name = "approved", columnDefinition = "bit", nullable = false)
public boolean isApproved() {
return this.approved;
}
public void setApproved(boolean approved) {
this.approved = approved;
}
}
现在我想使用QueryDSL来获取元组的数量。特别是我有这个QueryDSL查询
JPAQuery query = new JPAQuery(getEntityManager()).from(userAccountHasWorkgroup)
.where(userAccountHasWorkgroup.userAccountByUserAccountId.id
.eq(userAccountId));
其中userAccountHasWorkgroup
是QueryDSL的QUserAccountHasWorkgroup
实例。如您所见,查询是在一个字段上运行的,该字段是实体密钥的一部分。
以上查询在以下JPA查询
select userAccountHasWorkgroup
from UserAccountHasWorkgroup userAccountHasWorkgroup
where userAccountHasWorkgroup.userAccountByUserAccountId.id = ?1
我尝试运行代码:
query.count()
问题是此代码引发了以下异常
实体正确引用数据库中的表。
可能是什么问题?
谢谢