-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to dynamically obtain the class of a many-to-many...
PostPosted: Thu Jan 12, 2006 5:44 pm 
Newbie

Joined: Thu Jan 12, 2006 5:34 pm
Posts: 4
I wish to use Reflection to create a templating system that presets default values and associations between my beans in Hibernate 2. It would obtain field names and values from a text file, use Reflection to look up the setters and build criteria queries to obtain objects to assign in associations.

This breaks down in many-to-many and one-to-many schemes because reflection will only tell me that a given field takes a Set. Is there a way I can determine the class Hibernate expects to find in a given Set, so I can build a criteria query to obtain its members dynamically?

Thanks!

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 12, 2006 6:03 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
I am not sure if this is new in Hibernate 3 but you have access to the metaData of the mapping. In this case you would not need another file. Have a look in the reference. There is a chapter about this.


Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 12, 2006 7:35 pm 
Newbie

Joined: Thu Jan 12, 2006 5:34 pm
Posts: 4
Good lead, however, it gets me no further than I was before:

factory.getClassMetadata(Myclass.class).getPropertyType("myproperty") returns a Type, but from Type I can only get Set.class, not the class that's being mapped in the association.

I've read the docs up and down but don't see anything more promising. Am I completely blind?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 3:52 pm 
Newbie

Joined: Thu Jan 12, 2006 5:34 pm
Posts: 4
It took some thinking so I thought the answer to this may be useful to post. From the ClassMetaData object, one needs to getPropertyType of the association in the field, cast it into an AssociationType, and call getAssociatedClass.

I was staring at Type for an hour before I figured this out. I am particularly ignorant, but maybe others are too :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 5:52 am 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
Hi,

Some usefull links for you:

http://forum.hibernate.org/viewtopic.php?t=927780&highlight=persistentclass+configuration

http://forum.hibernate.org/viewtopic.php?t=937497&highlight=persistentclass+configuration

http://forum.hibernate.org/viewtopic.php?t=950543&highlight=

http://forum.hibernate.org/viewtopic.php?t=941099&highlight=

Read them carrefully, there's a lot of information what you might use.

If you don't find the solution post more details, maybe I can help you.[/url]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.