I have hibernate query, where I need to transform one column with date_trunc, however I don't know how to bind this transformed value to my joined entity object
Is there any possibility to pass this transformed column to mine hibernate entity?
Of course it's conceptual code in case it wouldn't make sens for you:
@Entity
class SomeClass {
private ZonedDateTime orderTime;
@ManyToOne(targetEntity = SomeStats.class)
@JoinColumn(name = "SOME_STATS_ID", referencedColumnName="ID")
private SomeStats someStats; // Class that I need aggregate
private long id;
// ... other fields that aren't grouped
}
class SomeStats {
private long id;
private double price; // I need to take average of this
private ZonedDateTime paymentTime; // And truncate this
}
I need some idea to make something similar to:
SELECT someclass.*, AVG(somestats.price), date_trunc('hour', somestats.payment_time) as timebucket
FROM SOME_CLASS someclass
JOIN SOME_STATS somestats ON somestats.id = someclass.some_stats_id
GROUP BY someclass.id, timebucket
but with average as SomeStats.price and truncated date as SomeStats.paymentTime, is it even possible?