How to get the column name for an entity attribute using Hibernate


#1

Hello, guys. Can someone help me. I want to create dynamic native sql builder. But i really can’t find, where hibernate holds db column names for attributes.
Thank you.

P.S. i use 5.2 hibernate. And solutions from other topic( https://stackoverflow.com/questions/46335682/how-to-get-column-names-of-jpa-entity ) don’t seem to work


#2

Ok. i found.

((AbstractEntityPersister)((MetamodelImplementor) entityManager.getEntityManagerFactory().unwrap(
SessionFactory.class).getMetamodel()).entityPersister(Reference.class))
.getPropertyColumnNames(“viewName”)

#3

Check out this article as well.