I have a result set that is returned from a pretty complex query which I would prefer to run using SQL rather than HQL.
Just for context - It is a suggestions result set that suggest replacing existing objects that the customer pays for, to another type of objects that may cost less. So for each suggestion per product there are 3 columns that repeat themselves - id
, type
, price
and 2 different columns that represent a suggestion - new_type
and new_price
.
My result set looks something like this:
id type price new_type new_price
------------------------------------------------------
1 14 90 12 85
1 14 90 11 87
1 14 90 7 73
2 9 80 7 73
2 9 80 4 52
I would like to map it to a Java object that looks something like this
class Suggestion {
private Long id;
private Integer type;
private float price;
private List<Replacement> replacements;
private class Replacement {
private Integer type;
private float price;
// getters, setters, constructors removed
}
// getters, setters, constructors removed
}
I'm not sure if Hibernate offers this kind of transformer out of the box (couldn't find one). I'm also not sure that writing a new transformer is the way to go.