Well, I hope you found a solution for your problem, given that it's been 6 years ;)
I had a similar problem, and your post came up near the top of the list when I googled "getId returns null hibernate" so I figured I'd post my findings in case it helps someone else searching on the same terms.
I was seeing the exact same issue with Hibernate 3.6.0.Final and JPA 2.0 - I had one entity derived from a superclass (marked with an @MappedSuperclass annotation). In that superclass, I had the id field declared like this:
Code:
@Id
@Basic(optional = false)
@Column(name = "objectid")
private Long id;
And then a getter with the following signature:
Code:
public final Long getId()
In my case, the problem was the final modifier. When the entity in question is a proxy, the getId() method cannot be overridden by the proxy's implementation. The proxy has a field called id (with value set to null) and so getId() returned null. For the entity's other properties, my getters were not declared final, and so the proxy's reflection black magic could work properly.
This behavior was sporadic - only certain test cases would cause a proxy to be instantiated, so tracking down the issue took some time.
I would consider this to be a case of silent failure. It would be nice if Hibernate would throw some kind of warning or exception on startup, such as "Getters for @Id fields cannot (should not?) be final".
At any rate, I hope this helps someone...