I have an entity call Student with few fields related to student and a list of Subject with oneToMany relation. Here i need to get all the fields including the List of Subject except "image" as it uses more memory it takes long time to retrieve all rows. Can some one say how to create Projection and criteria to retrieve this Student object without image field alone? Is there any custom result transformer like "AliasToBeanNestedResultTransformer"? As this will not work for my scenario where i am having List of Subject as OneToMany relationship.
@Entity @Table(name="STUDENT") public class Student { @id private long studentId; private String name; private String dob; private int age; @Lob private byte[] image; @Lob private byte[] imageTnail; @OneToMany(mappedBy="subject", cascade = CascadeType.ALL, orphanRemoval=true) private List<Subject> subjects; //setter & getter... } @Entity @Table(name="SUBJECT") public class Subject { @id private long subjectId; private String subjectName; @ManyToOne @JoinColumn(name="studentId") private Student student; } Edit
List<Student> results = getSession().createCriteria(Student.class) .setProjection( Projections.projectionList() .add( Property.forName("studentId")) .add( Property.forName("name") ) .add( Property.forName("dob")) .add( Property.forName("age")) ).setResultTransformer(Transformers.aliasToBean(Student.class)).list(); System.out.println("StudentDaoImpl.getStudents()"+results.get(0).getName());