This can be done in NHibernate (not Hibernate) as follows.
IList<string> classList = new List<string();
ICollection<PersistentClass> persistentClasses = Configuration.ClassMappings;
foreach (var persistentClass in persistentClasses)
{
foreach (var property in persistentClass.PropertyIterator)
{
if(property.Type.IsAssociationType == true && property.Type.ReturnedClass.Name == "GivenClassName")
{
classList.Add(persistentClass.EntityName);
}
}
}
return classList;
All the class mappings are retreived in a collection and are iterated to find associations between their properties and a given class.
I think Hibernate too has similar APIs so this can be done in Hibernate too.
Also note that this code is in C#, but I thought maybe looking at it you can write similar code in Java too.
See this answer which demonstrates similar APIs in Hibernate.