How can i get the Metadata of my Tables before they annotated to my Configuration?
I want to add my Entity's to my SessionFactory but i don't know the classes when i start the programm.
After i connect with Hibernate to the Database i want get the Metadata from the Database and use them for example to find the classes that i want to add.
This is the way how i get the Metadata but it only works if add the classes in the hibernate.cfg.xml or add them static in my HibernateUtil before i create the Session开发者_开发技巧factory.
Map metaa = qCon.getSessionFactory().getAllClassMetadata(); Set set = metaa.entrySet(); Iterator it = set.iterator(); while (it.hasNext()) { Map.Entry m = (Map.Entry) it.next(); // Do something with the values... }
Now i want to add the classes at runtime with addAnnotatedClass().
Is there any way to get the Metadata from the tables in the Database?
You can use plain JDBC connection to get database metadata. But that will give you table names, not entity names. If you can calculate entity class name from a table name, then you can use Class.forName(entityClassName)
.
精彩评论