Is it possible to do a one-to-one mapping to a property, not using primary keys? Basically, what i want to do is to have a property in my “Parent” class, which only holds one reference to one of its children, based on some rule. For example, it could be “last added child”. I know this is fairly simple to do with queries, but is it possible to have “intelligent” properties? So you dont have to write anything besides .load(Parent.class, pk) and then work with the instance from there on.
Same question applies for one-to-many relationships, would it be possible to apply rules for that as well? And finally, would it be possible to integrate these rules with paramenters to the getmethod?
So you could have a getChildren(from, to) ish method 🙂
I would try using the formula attribute. This will allow you to define more complex mappings by using SQL, columns, or other expressions. I’ll have to look into this more when I get home but here are some examples\articles to get you started. Apparently the source code also has examples at
org.hibernate.test.onetooneformulaMany-to-One Formula Forum Post
O’Reilly Hibernate 3 Formulas Article
Hibernate Example Mappings