i have a query like this. i pass the student ID i need some fields from Student as well as their parent as well some fields from the parent->Address[here is the main problem i am facing] i am using AliasToBeanNestedResultTransformer
transformer by Sami Andoni
here is the implementation of it CODE
here is my code.
public List<Student>searchForStudent(Integer studentId)
{
Projection p=Projections.projectionList().create()
.add(Projections.property("name"),"name")//the student name it works O.K
.add(Projections.property("lastname"),"lastname")//the student name it works O.K
.add(Projections.property("age"),"age")//the student AGE it works O.K
.add(Projections.property("p.phone"),"parent.phone")//the parent phone it works O.K
.add(Projections.property("address.state").as("parent.Address.state")); // i need a field from address.state here is the problem...
Session session = ......
Criteria like = session.createCriteria(Student.class).add(prepareForSelect())//some filters..
.createAlias("parent","p")//the parent of the student. a student have one parent
.createAlias("parent.Address","address")//the address of the parent.... a parent have one address.
.setProjection(p)
.setResultTransformer(new AliasToBeanNestedResultTransformer(Student.class));
List<Student>results=like.list();
return results;
}
it throws
Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.generic.model.Parent.Address
FYI is some type mismatch i have done some tracing in SAMI
code and i see this
[MyState]
[Address]
seems that Hibernate is returning a String State
MyState
in this case and the transformer is using a Address Object
and this is the type Mismatch.
is any help is hugely needed it
thanks a lot.
I have improved the SamiAndoni class, maybe it solve your issue
I hope it help you.
--------------edit 07/25/15---------------
To group nested list.
To speed up the process I´m suggesting throw a thread in the main process.
This is my Entity interface:
Usage example: