Determining the primary key property name using Hibernate

Simple method:

String idPropertyName = sessionFactory.getClassMetadata(User.class).getIdentifierPropertyName();

To get the actual value see this tutorial

Elaboration
Continue reading “Determining the primary key property name using Hibernate”