我有以下实体
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.Type;
@Entity
@Table(name = "Privilege", uniqueConstraints = @UniqueConstraint(columnNames = "name"))
public class Privilege implements java.io.Serializable {
private static final long serialVersionUID = 8357379972506504809L;
private Long privilegeId;
private String name;
private String description;
public Privilege() {
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "privilegeID", unique = true, nullable = false)
public Long getId() {
return this.privilegeId;
}
public void setId(Long privilegeId) {
this.privilegeId = privilegeId;
}
@Column(name = "name", unique = true, length = 45)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "description", length = 65535)
@Type(type="text")
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
}
映射MySQL DB中的表。 我正在尝试通过以下QueryDSL代码检索数据
public Privilege findByName(final String name) throws EntityNotFoundException {
Privilege workgroupPrivilege = new JPAQuery(getEntityManager())
.from(privilege)
.where(privilege.name.eq(name))
.uniqueResult(privilege);
if (workgroupPrivilege == null)
throw new EntityNotFoundException("Cannot find entity "
+ Privilege.class.getCanonicalName()
+ " with name <" + name + ">");
else
return workgroupPrivilege;
}
问题是findByName()
代码返回了Privilege Entity对象的实例,但其字段中的数据为null。
这意味着Entity-DB Table绑定已正确完成(其他我将拥有一个null Privilege Entity实例)。
编辑:
网络应用将此字段添加到空白的权限实例
handler = org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer@48f52e0b
这个增加的字段可能是解决问题的关键吗?
你可能遇到什么问题?
答案 0 :(得分:1)
由于延迟数据加载,调试器向我显示没有数据。