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 class mappings are deleted in the collection and repeated to find the relationship between their properties and the specified class. I think Hibernate also has similar APIs, so this can be done in Hibernate too. Also note that this code is in C #, but I thought that maybe looking at it you could write similar code in Java too.
See this answer for a demonstration of similar APIs in Hibernate.
source share