Any ideas why I would be experiencing flakiness with #getReference? Under some circumstances I can get an NPE when calling the methods of the object returned by #getReference. For example, I can run a unit test over and over and sometimes I will get an NPE and sometimes not.
If I use #find or #merge instead everything seems to be fine. Here's an example:
Code:
entityToOperateOn = em.getReference( MyEntity.class, anEntityPossiblyFromAnotherTransaction.getId() );
Sometimes when I call #getId on the entity to operate on I will get an NPE. If I change #getReference to #find or #merge it always works. Note that this is not deterministic, the failure only happens sometimes on the same exact code paths. Any pointers on what I should start looking into to resolve this?
TIA!