ObjectDB ObjectDB

Collection update does not increase entity version and is not persisted

#1

Hello,

I found a bug when adding elements to a collection of Entities:

Event {
    Collection<Attachment> attachments;

    void addAttachment(Attachment attachment) {
        this.attachments.add(attachment);
    }
}
Attachment {
    String filename
}

If I call this method (all classes are enhanced) the version of the event does not increase and the updated event is not stored in the database (retrieve the event shows that the attachments field is still empty).

You find a complete use case at http://www.objectdb.com/database/24436/support/24435. After Download please start the Tester. It loads an existing Event, adds an attachment via addAttachment() method and checks in another transaction if this change was written or not. If I change the code to use the setAttachments() it also fails.

This is very urgent for us since we already lost important data because of this bug.

Thanks in advance
Markus Ritter

edit
delete
#2

Your test case demonstrates an issue in tracking changes to a collection in an object of an old schema, in which the collection was not exist yet (as of changing attachment to attachments in Event).

As a workaround, you may want to move this initialization:

    private ArrayList<Attachment> attachments = new ArrayList<>();

to getAttachments():

public Collection<Attachment> getAttachments()
{
    if (attachments == null)
        attachments = new ArrayList<>();
    return attachments;
}

and update addAttachment and setAttachments to use getAttachments() instead of direct field access.

This workaround may fit as an urgent solution.

ObjectDB Support
edit
delete
#3

Hello,

this workaround helps but does not solve the core issue. Will there be a fixed version anytime in the near future?

Thanks in advance
Markus

edit
delete
#4

Please try build 2.7.3_03.

Note that using the suggested workaround is recommended as it is more efficient. If the ArrayList is initialised as in your original code, ObjectDB has to fall back to tracking changes by comparing object snapshots, which is less efficient.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.