Hi people. Firstly, I want to thank you people for this amazing work on hibenate. It's really COOL.
Well I'm Newbie. I'm trying to find a good example (or advise) of the old role problem mapping something like this:
Person -> one-to-many -> Role -> many-to-one -> RoleType
idperson (pk) idRole (pk) roleType
name fkperson
fkroletype
roleInformation
...
This is my relational database and my trivial mapping was that generated by "hibernate synchronizer".
What I want to do is create logical one-to-one relations btw Person and role representing the RoleType. My motivation is that I really dislike doing something like
Person p =...
fatherRole =...query(p.getRoles(),"Where fkroletype='father'")
print(fatherRole.getRoleInformation);
I want to code thos w/o sql (if it's possible :). Something like
Person p=...
fatherRole = p.getAsFather();
//fatherRole will be null if he is not a father
well, Is it possible to be done?
I see that I can put where clauses in the mapping for sets, but it will result in something odd like:
p.getFatherRole()[0]
Also i give up inheritance solution since conceptualy, it's more like an interface. I don't want to code each possible combination btw roletype and person as a class. And i can't use where clauses in subclasses anyway. But I can afford to code method accessors (one-to-one).
By the way, any links to examples (not the usual ones in the source distribution, that I got already) will be apreciated. The same for any new tutorials or blogs.
Thanks.
|