Bugs item #837092, was opened at 2003-11-06 10:06
Message generated for change (Comment added) made by adrianprice
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=837092&group_id=22866

Category: JBossCMP
Group: v3.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Adrian Price (adrianprice)
Assigned to: Nobody/Anonymous (nobody)
Summary: CMP Field Update Optimization is Broken

Initial Comment:
The mechanism for optimizing updates to CMP fields is
broken, because it makes the erroneous assumption that
the value being stored is immutable.

o.j.e.p.c.j.b.JDBCFieldBridge.setInstanceValue() or
thereabouts ignores the update if
oldValue().equals(newValue).  Whilst this works for
primitives (or rather their immutable java.lang.*
wrappers), it breaks completely for mutable
serializable objects in a BLOB, because if one
retrieves such an object from a CMP field, modifies it
then updates the CMP field with the same, modified
object, that change will never get flushed to the
database and the update will have been ignored.

class MyBean implements Serializable {
    int x, y;
    // getters & setters...

    // The correct implementation of equals() for this
class.
    public boolean equals(Object o) {
        if (!(o instanceof MyBean))
            return false;
        MyBean that = (MyBean)o;
        return this == that || this.x = that.x &&
this.y = that.y;
    }
/*
    // Horrid kludge necessary to force JBossCMP to
store me :(
    public boolean equals(Object o) {
        return false;
    }
*/
}

MyEntityLocal entity =
MyEntityLocalHome.findByPrimaryKey(pk);

// Retrieve bean from CMP field and modify it.
MyBean bean entity.getBean(); // CMP field getter
bean.x = 666;
bean.y = 777;

// Store modified bean. Setting field to null first
forces JBossCMP 
// to recognize the update in 3.0.4 and 3.2.1, but not
3.2.2.
entity.setBean(null); // (shouldn't be necessary anyway)
entity.setBean(bean);

// TXN commit...

// asserts fail, bean not persisted.  Uncommenting
Horrid Kludge forces JBossCMP v. 3.2.2 to recognize &
persist the update.
bean entity.getBean();
assert(bean.x == 666 && bean.y == 777);


----------------------------------------------------------------------

>Comment By: Adrian Price (adrianprice)
Date: 2003-11-06 10:10

Message:
Logged In: YES 
user_id=580837

penultimate line should read:
bean = entity.getBean();

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=837092&group_id=22866


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to