| I see your point and understand the problem, but I'm afraid there is no easy solution in that scenario. JPA requires reference equality i.e. when getReference returns an object with an identity, it always has to stay the same object while it is managed. One thing you could do though, is inspect the object, check if it is a proxy, and if so, load it by doing EntityManager.find. I don't know how Hibernate could help you with this. One thing you could do, is map the ToOne as insertable=false, updatable=false and control the FK via an id property instead, but that has the potential for introducing other problems. If you have a different idea how this could be handled, please tell us. |