get database metadata using hibernate

2019-08-13 15:14发布

问题:

I need to get column names from a table, I referred this link here: http://www.kodejava.org/examples/163.html

It shows using jdbc to get the metadata, I want to know is there any hibernate method similar to this? I am having mysql and oracle as the databases.

回答1:

You can use the following codes:

String[] columnNames = sessionFactory.getClassMetadata(Java.class).getPropertyNames();

Type[] columnTypes = sessionFactory().getClassMetadata(Java.class).getPropertyTypes();


回答2:

String[] columnNames = getSessionFactory().getClassMetadata(Employee.class).getPropertyNames();

org.hibernate.type.Type[] columnTypes = getSessionFactory().getClassMetadata(Employee.class).getPropertyTypes();