Hibernate version:3.1.3
Hi all
for my project at
https://genericrcp.dev.java.net/ I need mapping information from the mapping files. Based on this info a generic gui will be generated. I parse the hbm.xml files manually to get this infos e.g. wich classes, simple attributes or kind of relationsships (otm, mtm ...)
Now I rec ognized that I can use the hibernate Configuration object to get the mapping info and don't have to parse the files by myself.
With this following code I've access to the mapping info especially on relations like ManyToOne and OneToMany.
Configuration cfg = new Configuration();
for (Iterator iter = cfg.getClassMappings(); iter.hasNext();) {
PersistentClass hPc = (PersistentClass) iter.next();
...
for (Iterator iterator = hPc.getPropertyIterator(); iterator.hasNext();) {
Property prop = (Property) iterator.next();
if (prop.getValue() instanceof ManyToOne) {
ManyToOne mto = (ManyToOne) prop.getValue();
}
if (prop.getValue() instanceof org.hibernate.mapping.Set) {
org.hibernate.mapping.Set set = (org.hibernate.mapping.Set) prop.getValue();
if(set.getElement() != null && set.getElement() instanceof OneToMany) {
OneToMany otm = (OneToMany) set.getElement();
}
}
}
My problem now is how do I know when a relation is Many-To-Many and wich Class of objects are in the Collection.
I don't found a class Many-To-Many and set.getElement() returns null when relation is MTM.
Thanks a lot.