1) a relationship to a Branch should be mapped on the DB schema with two columns: the Branch composite id [TREE_ID, BRANCH_ID], in the case of Tree entity, it already have the TREE_ID value (since it is its primary key), so it will be so clever to not duplicate the TREE_ID column?
2) How should I map the inverse @OneToOne relationship "lastBranch" from Branch to Tree? Should not map it because it's already mapped by the @ManyToOne tree?
PS: Surely some of you would suggest to dinamically extract in someway the last branch from the branches list, using some "age" attribute, sorting it, and getting last element.. but I want a more performant solution, and a solution i can use easily from HQL and OGNL, something like this:
I think that the @Formula solution can have some performance issues.. so i would like to phisically add this @OneToOne relationship on the tables..
Joined: Dec 14, 2007
can think a simple solution to the problem - use order by in braches by date (in hbm file) and pick the last one from collection wherever needed.
otherwise, write a getLastBranch in Tree class which loops through your branches to find the last branch and return. - These is a very light weight solution.
afik, for one to one you must find a unique identifier in the child table as well that differentiates the unique rows involved (in your case last created branches). I hope date field or id field might not help in your case. Hope this helps.
"It's been so long since I've done a good thing--the right thing" : Tears Of Sun