map incomplete fields to class in hibernate
Sometimes you just want to partially use columns or fields in HQL
but still want to map them into a class by Hibernate.
Well I also encounter this situation.
I have a entity class Word
which has 5 fields:
1 |
|
But my Criteria
method only has two:
1 |
|
You will surely get a Exception:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to rugal.entity.Word
To solve this we need a transform class, namely:
1 |
|
This could just be a POJO, with the number and same alias in you Criteria
method.
Then we need to register it in Criteria
method, say:
1 |
|
Now have a try if this is workable or not!
map incomplete fields to class in hibernate
https://rug.al/2014/2014-12-12-map-incomplete-fields-to-class-in-hibernate/