These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to find the inverse property
PostPosted: Thu Mar 30, 2006 10:33 am 
Newbie

Joined: Thu Mar 30, 2006 10:12 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.