Hibernate version: 3.1.3
Hi all,
I'm trying to find the inverse property of a bi-directional relation using the hibernate meta-model.
Example: I have a class Person and a class House. There is a bi-directional relation between person and house with roles Person.address and House.inhabitants. This relation is nicely mapped using a bi-directional relation. Give the property House.inhabitants, how do I know that Person.address is the inverse property?
First attempt:
ClassMetadata meta = sessionFactory.getClassMetadata("House");
// assume that i corresponds to the index of property "inhabitants"
CollectionType hibernatePropertyType = (CollectionType)meta.getPropertyTypes()[i];
String entityName = hibernatePropertyType.getAssociatedEntityName(sessionFactory);
// Person
String longPropName = hibernatePropertyType.getRole();
// House.inhabitants
And how do I get "address" ?
Previously I tried
hibernatePropertyType.getLHSPropertyName();
But under 3.1.3 this returns null because it is only filled in in case you use a property-ref in your mapping doc, i.e. if you have a foreign key pointing to a non-primary key. And that is also what the doc says :-).
Hibernate can find this information by comparing the columns of the one-to-many with those of the many-to-one. But I don't seem to find the right API to do that.
Any ideas?
thanks,
Bert
|