I want to take Nested object values in Hibernate Projection List. I having Pojo \'Charge\' and \'Tariff\' class with OneToMany and ManyToOne relations.
My sample cod
My solution is very basic. It's not as clean as a proper result transformer but it's useful when you just need to do a quick projection for a few properties.
Instead of .add(Projections.property("tariff.amount"),"amount"))
type .add(Projections.property("tariff.amount"),"tariffAmount"))
Then, just add a setter on your root object "setTariffAmount".
public void setTariffAmount(String tariffAmount) {
this.tariff = (this.tariff==null) ? new Tariff() : tariff;
tariff.setAmount(tariffAmount);
}
The drawback is that it "dirties" your object with extra methods.