-->
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.  [ 2 posts ] 
Author Message
 Post subject: Is there a way to know all the objects in my unit that have
PostPosted: Thu Jun 07, 2007 3:03 pm 
Regular
Regular

Joined: Wed May 02, 2007 2:42 pm
Posts: 101
reference to a Object?

This is not directly related to hibernate , but there are a lot of smart developer here.

I need a way (maybee the ORM can help me in this) to know all the entity in my unit that has reference to a given object.

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 3:30 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

In my opinion this does sound possible via the Java Reflection API so long as you can extract/discover the classes that are managed by a particular persistence unit.

Once you have the class names, you can create a .class, and then introspect it/them. Assuming you have the Object defined as a class level variable (with a particular variable name) you can call (not used the reflection API, so this might not be 100% acurate) <class object>.getFields() which will return the fields, then you have to loop over them checking for the one you are searching for.

Annother similar option would be to declare your own custom annotation and annotate the reference to the object you want to search for like so:

Code:
@MyCustomAnnotation
Obect foo


You can then use the reflection API to search for your custom annotation.

Hope that helps,

Andy

_________________
Rules are only there to be broken


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