Determining the primary key property name of an entity bean using reflection

The name of the property that represents the primary key of an Entity Bean can be determined using reflection as follows:

To get the actual value see this tutorial

The bean must have the @Id (javax.persistence.Id) annotation on either the property member or the getter method. (The annotation is not permitted on the setter method).

 

For a simpler method that uses Hibernate see this tutorial. (See the same tutorial for an example of an Entity bean if unsure)