SourceForge.net Logo
Main Overview Wiki Issues Forum Build Fisheye
Issue Details (XML | Word | Printable)

Key: CMP-930
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Shay Banon
Reporter: David Mack
Votes: 1
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Compass

Collection component with duplicate entities is unmarshalled incorrectly

Created: 25/Mar/10 05:15 PM   Updated: 05/Aug/11 03:52 PM
Component/s: Compass::Core
Affects Version/s: 2.2.0 GA
Fix Version/s: None

File Attachments: 1. Text File cmp-930.patch (8 kB)
2. Zip Archive test.zip (3 kB)



 Description  « Hide
See attached test. Boils down to:
class A {
    int id;
    List<B> bList;
}

class B {
    int id;
    String name;
}

    <class name="A" alias="a">
        <id name="id" accessor="field"/>
        <component name="bList" ref-alias="b" accessor="field"/>
    </class>

    <class name="B" alias="b" root="false">
        <id name="id" accessor="field"/>
        <property name="name" accessor="field">
            <meta-data>name</meta-data>
        </property>
    </class>

// Test
        B b1 = new B("value1");
        b1.id = 2;
        B b2 = new B("value2");
        b2.id = 3;

        A a = new A();
        a.id = 1;
        a.bList = new ArrayList();
        a.bList.add(b1);
        a.bList.add(b1);
        a.bList.add(b2);
        session.save(a);

        a = (A) session.load(A.class, "1");
        B b = (B) a.bList.get(0);
        b = (B) a.bList.get(1);
        b = (B) a.bList.get(2);
        assertEquals(3, b.id);
        assertEquals("value2", b.name);

You would expect the third record in bList two have id=3 and name="value2", but it has id=3 and name="value1". I traced this down to the fact that the unmarshaller tries to cache entities. When it loads the second instance of B(id=2), it finds it in the cache already and does not unmarshall it. However, this has the side-effect of not incrementing the counter for the "name" property. Then, when the third member of bList B(id=3) is loaded, the counter is still pointing at the name value for the second instance of B(id=2).



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Lyle Hanson added a comment - 19/May/10 05:05 PM
We just got bit by this one as well.

Lyle Hanson added a comment - 05/Aug/11 11:36 AM
Attached is a patch which I believe resolves this issue.

In light of the fact that this patch is unlikely to be applied here and see an official release, I've applied it to my own fork here: https://github.com/lhanson/compass and I've also published a release in Maven Central so I can resolve production issues I've had as a result of this bug (more info in the readme in my fork).


Shay Banon added a comment - 05/Aug/11 02:09 PM
Actually, I moved compass to be in github at: https://github.com/kimchy/compass, so if you send a pull request, I will be happy to apply it. That way we can keep a central place for patches.

Lyle Hanson added a comment - 05/Aug/11 03:52 PM
Aha. I wish I'd found that repository before I created an independent fork, but a cursory search on GitHub didn't turn it up.

You may want to update the project homepage to change the SVN link to point to the current official repository so folks know the codebase isn't dead. It seems as though developers have expressed interest in helping with maintenance and would be willing to do so if they knew it was encouraged.