hibernate-6.x

Class metadata in Hibernate 6 using AbstractEntityPersister


I'm in the process of migration from Hibernate 5.6 to 6.2. I have a utility class that via a deprecated call to

entityManager.unwrap(Session.class).getSessionFactory().getClassMetadata(clazz)

was obtaining an instance of AbstractEntityPersister with which I had access to methods like:

  1. toColumns
  2. getPropertyNames
  3. getPropertyColumnNames
  4. getPropertyNullability
  5. getIdentifier
  6. getPropertyValue

What is the proper way to have access to these methods in Hibernate 6? Is there another recommended API alternative to all these methods?

What I tried was working with entityManager.getMetamodel().managedType(clazz) but I only had partial success, or access to methods that seem to only help me do my own implementation of the needed methods.


Solution

  • This is worked for me

    AbstractEntityPersister persister = ((AbstractEntityPersister) ((MappingMetamodel) sessionFactory.getMetamodel()).getEntityDescriptor(clazz));