Reading Hibernate entity id value

Does the Hibernate API have an entity identifier field value for reading? In my case, this will be the value Serializablereturned by the field annotated with @Id. For example, suppose I have an object Person:

class Person {
    @Id private long id;
    // ... other fields, getters/setters, etc ...
}

Person p = new Person();
p.setId(42L);

Hibernate.unknownFunction(p); // returns 42L

Of course, I could read the annotations to find the field @Idmyself, but it looks like it could be inline.

+5
source share
3 answers

session.getIdentifier(object)

Gets the value of the identifier of this object associated with this session. An exception is thrown if this instance of the object is temporarily or disconnected relative to this session.

, . , .

+2

, , id , , . :

public interface IdHolder {
    Integer getId();
}

.

cglib - , .

+2

, 100% , , @Id; , , , @EmbeddedId. , , id?

0

All Articles