We're updating the issue view to help you get more done. 

Using unproxy in getter does not work properly

Description

Unproxying a lazyly loaded object in a getter method was never a problem up to version 5.1, but in 5.2 Hibernate somehow tries to delete an associated object (OneToOne) from the database although the association was never changed.

Please have a look at the test case I created, I think this should make it clear: https://github.com/mpe85/hibernate-unproxy-problem (Test class JPAUnitTestCase)

Relevant code snippet:

1 2 3 4 @OneToOne(cascade=CascadeType.ALL, orphanRemoval=true, fetch=FetchType.LAZY) public Child getChild() { return (Child) Hibernate.unproxy(child); }

Note: Hibernate.unproxy() was introduced in 5.2, the 5.1 (and prior) code of course looked like this:

1 ((HibernateProxy)entity).getHibernateLazyInitializer().getImplementation();

I guess Hibernate expects the getter to return the proxy, but finds the unproxied object and concludes the association was altered (causing the deletion attempt of the child).
Hibernate should treat the proxy object and the unproxied object as the same object like in 5.1 or earlier so that the unproxying can still be done in the getter (which is very nice because it is a very central place and the caller does not have to care about unproxying).

Please clarify if this is a bug or if this behaviour was introduced intentionally.

Environment

None

Status

Assignee

Chris Cranford

Reporter

Marco Perazzo

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

5.1.10

Components

Affects versions

5.2.10

Priority

Major