开发者

How can i get the Metadata of my Tables before they annotated to my Configuration?

开发者 https://www.devze.com 2023-03-04 14:03 出处:网络
I want to add my Entity\'s to my SessionFactory but i don\'t know the classes when i start the programm.

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消