Enhancer dirty tracking doesn't work with inherited entities

Description

Given these two classes:

@Entity private static abstract class Person { @Id private String name; @Version private long oca; public Person(String name) { this(); this.name = name; } protected Person() {} protected void setOca(long l) { this.oca = l; } } @Entity private static class Employee extends Person { private String title; public Employee(String name, String title) { super(name); this.title = title; } public Employee() {} public void setTitle(String title) { this.title = title; } }

Then this code:

Employee charles = new Employee( "Charles", "Engineer" ); charles.setOca( 1002 );

One would expect the "title" and "oca" fields to be dirty. However, Hibernate says only the "oca" field is dirty.

It appears the enhancer's dirty checker doesn't correctly handle inherited fields.

Here's a pull request which includes a test case demonstrating the issue: https://github.com/hibernate/hibernate-orm/pull/1654

Web links

Activity

Show:

Former user March 15, 2017 at 12:21 AM

Fixed in 5.1 branch as well.

Luis Barreiro January 18, 2017 at 8:01 PM
Edited

I've open HHH-11404, similar to this one but for MappedSuperclass. The same fix solves both. The test case is still useful. Thanks!

Craig Andrews December 2, 2016 at 8:49 PM

I've updated my pull request with the fix. All tests now pass.

Craig Andrews December 2, 2016 at 7:50 PM

This issue is very similar to https://hibernate.atlassian.net/browse/HHH-10977#icft=HHH-10977 - the order that classes are enhanced changes the result of which fields appear as dirty in the test I've provided.

EnhancerImpl.alreadyEnhanced needs to be changed to account for the case that a superclass of the class is enhanced but the class itself is not enhanced.

Fixed

Details

Assignee

Reporter

Fix versions

Affects versions

Priority

Created November 29, 2016 at 9:31 PM
Updated March 15, 2017 at 12:34 AM
Resolved March 15, 2017 at 12:21 AM