I have the following Entity
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;
}
}
which maps a table in a MySQL DB. I'm trying to retrieve the data though the following QueryDSL code
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;
}
The problem is that the findByName()
code returns me an instance of the Privilege Entity object but the data in its fields are null.
This means that the Entity-DB Table binding is correctly done (otherwhise I would have had a null Privilege Entity instance).
EDIT:
The web app adds this field to the empty instance of Privilege
handler = org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer@48f52e0b
May this added field be the key to solve the problem?
What can be the problem for you ?
The debugger was showing me no data because of lazy data loading.