I am not sure if this can be done in JPA. I have a query that will always be executed. I can execute in the DAO and set the results as a field. For example, Product entity doesn't have an attribute Offer in the database. But a list of Offers, is retrieved and set for that entity. So that I can say:
Code:
List<Offer> offers = myProduct.getOffers() ;
Currently, I run a complex sql native query to get offers for that Product, and call
Code:
myProduct.setOffers(retrievedOffers) ;
It will be nice to learn how to do it (if possible) using mapping. For example :
Code:
<attributes>
<one-to-many name="offers" fetch="LAZY" mapped-by="product_id">
<!-- Some code here to map offers to the result of a query -->
</one-to-many>
</attributes>
The query is complex and done with SQL.
Thank you.
Some expert can answer this question in a minute. What is going on ? I see a lot of hibernate experts on this forum !