Hi I am doing a project using Hibernate and Jersey.
In the service layer I am getting a 'LazyInitializationException'. I searched a lot about it.
I saw a solution for creating custom AccessorType. But still I am getting the exception.
Can anyone help me??
I am including more details about it.
Bean: User
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlAccessorFactory(XmlAccessorFactoryImpl.class)
public class User {
private String userName;
private String password;
private String email;
private String fname;
private String lname;
private Set<MachineTemplate> machineTemplates;
private String photoUrl;
public User() {
machineTemplates = new HashSet<>();
}
public User(String userName) {
this.userName = userName;
}
public User(String userName, String password, String email, String fname,
String lname) {
this.userName = userName;
this.password = password;
this.email = email;
this.fname = fname;
this.lname = lname;
this.machineTemplates = new HashSet<>();
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public Set<MachineTemplate> getMachineTemplates() {
return machineTemplates;
}
public void setMachineTemplates(Set<MachineTemplate> machineTemplates) {
this.machineTemplates = machineTemplates;
}
public String getPhotoUrl() {
return photoUrl;
}
public void setPhotoUrl(String photoUrl) {
this.photoUrl = photoUrl;
}
}
DAO Layer method
public User get(String uName) {
Session session = getSessionFactory().openSession();
User u = (User) session.get(User.class, uName);
session.close();
}
Service Layer method
@GET
@Path("/{userName}")
@Produces(MediaType.APPLICATION_JSON)
public User getUserInfo(@PathParam("userName") String userName) {
return userHelper.getUser(userName);
}