Skip to content
Advertisement

Hibernate upgrade to 5.2 – Session Factory creation and replacing PersistentClass for getting entity class properties

I am currently upgrading my Hibernate version to the latest version 5.2.10. I replaced my code in the HibernateUtil for the SessionFactory creation.

4.3.11.Final (Previous):

JavaScript

5.2.10 Final (New):

JavaScript

Now I have a method which would fetch me the list of column names by passing the DB table name as a string. I did it like this before in 4.3.11.Final:

JavaScript

Now after the upgrade it shows the method getAllClassMetadata as deprecated and am facing difficulty to get the PersistentClass object. I saw a similar question here but I couldn’t exactly figure out the solution. What part of my current code do I have to change for my getColumnNames() method to work exactly like before. I referred the documentation and it says to use the EntityManagerFactory.getMetamodel() instead but i can’t find suitable reference examples of the same. Also will I have to change the SessionFactory creation mechanism for this?

Advertisement

Answer

Well finally I did it thank’s to Vlad’s article. I took the integrator code without any change and modified my HibernateUtil and the getColumns() method. So here’s my code:

SessionFactory creation:

JavaScript

Metadata Extractor(Get Column names):

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement