Bug 259 : NASTY BUG: You lose some changes on a "partial object" when modifying an unloaded property
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
2.5.1
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
24/03/2010
Updated 
24/03/2010
Type 
Bug
 
Attachments 
No attachments

Test case:

public void test() {
        
        ResetBasicData.reset();
        
        List<Customer> custs = Ebean.find(Customer.class).findList();
        
        Customer customer = Ebean.find(Customer.class)
            .setId(custs.get(0).getId())
            .select("name")
            .findUnique();
        
        BeanState beanState = Ebean.getBeanState(customer);
        Assert.assertTrue(!beanState.isNew());
        Assert.assertTrue(!beanState.isDirty());
        Assert.assertTrue(!beanState.isNewOrDirty());
        Assert.assertNotNull(beanState.getLoadedProps());
        
        customer.setName("dirtyNameProp");
        Assert.assertTrue(beanState.isDirty());
        Assert.assertTrue(beanState.getChangedProps().contains("name"));
        
        customer.setStatus(Customer.Status.INACTIVE);
        
        Assert.assertTrue(beanState.isDirty());
        Assert.assertTrue(beanState.getChangedProps().contains("state"));
        Assert.assertTrue(beanState.getChangedProps().contains("name"));
        
    }

The final Assert fails as the change to the "name" property is lost (due to a reset of the bean state as part of the lazy load that is invoked when setting the "state" property (which was not part of the initial load)).

 
Rob 24 Mar 22:47
Fixed in HEAD

Fixed in HEAD.

The issue was in SqlTreeNodeBean.

For lazy loading and refreshing beans... we need to turn off interception temporarily ... and then turn it back on when finished.

The bug was that instead of turning back on ONLY interception, the code instead setLoaded() which turns on interception but also resets the internal bean state and specifically we lose the 'changedProps'.

The fix was to JUST turn back on interception (and not use setLoaded()).

woResponse

Upload a file