Hibernate Version: 3.2.7Get the list of all the tables a persistable entity can affectI want to get the list of all the tables, any action on a persistable entity can affect, I have tried the following approach:
String[] Function(String entityName, Session)
1. Add entityName to a list.
2. Iterate over list. For each in list
i. To handle cycle, If entityName has already been processd, move to process next item in the list.
ii. Get ClassMetadata using sessionFactory.getClassMetadata(entityName).
iii. If metaData is null, move to process next item in the list.
iv. If metaData is instance of AbstractEntityPersister, get the table name of the entity using persister.getTableName() and add to response array. Proceed to check if
there are associations.
v. Get the list of properties, For each property,
a. Load the Type of the property
b. If type is Association as well as Entity,add entityType.getAssociatedEntityName() to the list
If type is Association as well as Collection, add colltype.getAssociatedEntityName(factoryImplementor) to the list
If type is component, add componentType.getReturnedClass().getName() to the list
vi. Mark the entityName processed.
I am getting stuck when a property is mapped like this:
<array table="">
This property is identified as a collection but getAssociatedEntityName method fails with exception message: "collection was not an association". Then, I tried to handle for such types with if(type is ArrayType), I am not able to figure out how to get the associated table name in that case.
Since this, I have also learnt that getClassMetadata has been deprecated. Please suggest as to how to make this possible. I am yet to try with EntityManagerFactory.