I have two tables which have ManyToOne relationship. I need to shows specific rows of my ManyToOne relationship, but nothing will be shown in neither the page nor the console. (It does not even show the generated SQL although Hibernate shows the generated SQL of other parts of my code)
Project.java
@Entity
@Table(name = "Project")
@DynamicUpdate
public class Project implements Serializable{
private int id;
private String Name;
private Developer developer;
@Id
@GeneratedValue
public int getID() {
return id;
}
@ManyToOne(cascade = CascadeType.ALL)
public Developer getDeveloper() {
return developer;
}
....
}
Developer.Java
@Entity()
@Table(name = "developer")
@DynamicUpdate
public class Developer implements Serializable {
private int id;
private String name;
@Id
@GeneratedValue
public int getID() {
return id;
}
.....
}
Model.Java
Criteria criteria = session.createCriteria(Project.class, "project")
.createAlias("project.developer", "developer");
try{
ProjectionList pl = Projections.projectionList();
pl.add(Projections.property("project.id").as("id"));
pl.add(Projections.property("project.name").as("name"));
criteria.setProjection(pl);
criteria.setResultTransformer(new
AliasToBeanResultTransformer(ListOfProjectsSearchResult.class));
criteria.add(Restrictions.eq("developer.id", 1));
}catch(Exception e){
e.printStackTrace();
}
return criteria.list();