I'm working in a Java application using Hibernate 3.6.9 as ORM and xml mappings. Actually, having two entities, Detectable and Revision, Detectable has a one-to-many relation with Revision, having its entire set of done revisions mapped:
<set name="_Revisions" table="trevision" inverse="true" lazy="true">
<key>
<column name="id_detectable" />
</key>
<one-to-many class="com.company.model.tasks.Revision" />
</set>
Refer also to this similar question I posted. What I want now is to get the last of that revisions in a separate field of the class:
<many-to-one name="_LastDoneRevision" column="id_detectable"
class="com.company.model.tasks.Revision" lazy="false" />
What I want to achieve with that is to have the last revision (which I use in most of the cases) always eagerly fetched. Apart from that I could get the whole set of Revisions if I want, but it's lazily initialized by default. To achieve this, it might be necessary to use a custom query to get the last revision done from the whole set.
I think that can't be achieved with formulas, because they just retrieve a value, not a whole Entity. I want to be able in some way to choose what the many-to-one
relation should have.
A solution could be to use a view instead of the Detectable table itself. That way I could have a VDetectable entity which would be mapped against the view and the view could obtain all the original attributes plus the reference to the Revision I'm interested in.
Anyway, is it possible to have it loaded using only the original entity?