I use Hibernate and I have a problem: when loading an object using Session.load , the getter identifier returns null .
My objects inherit from the following interface:
public interface Entity { Object getId(); }
An example of an object that implements this interface:
@javax.persistence.Entity @javax.persistence.Table(name = "`Dog`") public class Dog implements Entity { private java.util.UUID id; @javax.persistence.Id @javax.persistence.GeneratedValue(generator = "uuid") @org.hibernate.annotations.GenericGenerator(name = "uuid", strategy = "uuid2") @javax.persistence.Column(name = "`Id`", nullable = false) @Override public java.util.UUID getId() { return this.id; }
The getId getter in the object implements the getId interface, but changes the type of the return value.
When I load this object using Session.load , getId returns null when calling Dog.getId , but not when calling Entity.getId .
Dog dog = (Dog)session.load(Dog.class, id); assert dog.getId() != null;
When I trace the execution of dog.getId() , it is not processed by the proxy server, but goes into the actual implementation. Thus, it gets the id field value on Dog , which is null , because it is a proxy.
Why is this?
source share