Is it possible for us to find what are the primary key fields for a Hibernate entity programmatically (similar to JPA’s PersistenceUnitUtil)?
Is it possible for us to find what are the primary key fields for
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
SessionFactoryprovides an method called getClassMetadata() to get the meta-data object for a class (i.e. ClassMetadata)To get the name of the identifier properties of an entity , use ClassMetadata.getIdentifierPropertyName()
To get the value of the identifier properties for an managed entity instance , use ClassMetadata.getIdentifier(Object entity, SessionImplementor session)
For example :
Suppose you have a managed entity instance that is loaded from a session :