Resolving a proxy does not update references from managed entities

Let’s say that within a transaction:

  1. I retrieve an entity a1 of class A from the database.
  2. The object a1 is managed, and has a reference to an object b1 of class B that is a proxy
  3. I can do a1.getB() and that returns a proxy, I can even do a1.getB().getC() and get another proxy

All that fine.

Now, if I get b1 from the database using the primary key, I get an unproxied instance. However, all references from the persistence context still point to the b1 proxy instance. So now, I have 2 managed versions of b1, one being a proxy and another not.

Is this expected?

Thank you in advance!

That’s unexpected. Please create an issue in the issue tracker( with a test case(hibernate-test-case-templates/ at main · hibernate/hibernate-test-case-templates · GitHub) that reproduces the issue.