-->
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.  [ 4 posts ] 
Author Message
 Post subject: mapping of collection and class
PostPosted: Wed Mar 18, 2009 4:34 am 
Beginner
Beginner

Joined: Mon Mar 02, 2009 3:36 pm
Posts: 25
Hi ,

i have declared a set in my *.hbm.xml file and mapped it with a class as one to many . using configuration properties i want to know that to which class this collection is mapped ??? could anybody please tell me how to proceed ???

Thanks,
Ganesh


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 18, 2009 6:43 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Do you mean: at runtime you have a Set object and you want to know the class to which this Set object is mapped (owner of this Set object)

For this you can do this:

Code:
public Class getOwnerClass(java.util.Collection c) {
    if(c instanceof PersistentCollection) {
        return c.getOwner().getClass();
    }
    return null;
}

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 18, 2009 1:24 pm 
Beginner
Beginner

Joined: Mon Mar 02, 2009 3:36 pm
Posts: 25
No i don't want to know the owner of the collection ..

i am putting my problem through an example :

i have a "Person" class which has a set named "addresses" and this set is mapped to the "Address" class in the person.hbm.xml file . now at run time ,using configuration property i am able to list all the collections which are declared in mapping file and owner entity name of the collection but i am not able to know that the content of the collection . i.e i want to know that the set named "addresses" is declared to hold the "Address" Object .

If you want to see my code i will paste it here .

Thanks,
Ganesh


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 19, 2009 12:33 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
May be this will give you wht you want:
Code:
collection.getCollectionType().getElementType(
                     (SessionFactoryImplementor) HibernateUtil
                           .getSessionFactory()).getName()

collection is of type org.hibernate.mapping.Collection

_________________
Regards,
Litty Preeth


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

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.