Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Zero Fetched Subobjects (with MongoDB+XML Mappings)

Thank you, James! Obviously, that was in fact my problem. In lieu of proper documentation, I have now taken to trudging through that XSD, and trying to decipher it, to tackle other problems I've been having too. That was very helpful, thank you.

Maybe I'll throw out today's problem to see if it rings a bell. Again, using EL2.5+Mongo+XML Mappings, I have an object with a subobject (not embedded) and it persists correctly to Mongo:

<entity name="Waction" class="com.x.waction.Waction">
    <no-sql data-format="MAPPED" />
    <attributes>
        <id name="_id">
            <generated-value />
        </id>
        
        <many-to-many name="events" fetch="EAGER" target-entity="com.x.event.Event">
            <cascade>
                <cascade-all />
            </cascade>
        </many-to-many>
    </attributes>
</entity>

<entity class="com.x.event.SimpleEvent">
    <no-sql data-format="MAPPED" />
    <attributes>
        <id name="_id">
            <generated-value />
        </id>
        <basic name="timeStamp" />
    </attributes>
</entity>

In Mongo, after persisting, I see the primary object and the subobject, with the proper link between them:

> db.WACTION.find().pretty()
{
"_id" : ObjectId("51a8d63b3004eef2587bcdd0"),
"_ID" : "51A8D63B3004EEF2587BCDCE",
"EVENTS__ID" : [
"51A8D63B3004EEF2587BCDCF"
]
}
> db.EVENT.find().pretty()
{
"_id" : ObjectId("51a8d63b3004eef2587bcdd1"),
"DTYPE" : "SimpleEvent",
"TIMESTAMP" : NumberLong(0),
"_ID" : "51A8D63B3004EEF2587BCDCF",
"DBID" : "null"
}

But when I select the WACTION from the database, it comes back with an "events" list containing zero items:

EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
Object result = em.find(Waction.class, objectId);
if(result instanceof Waction) {
    Waction w = (Waction) result;
    List<Event> evs = w.getEvents();
    int evsSize = evs.size();
...

and 'evsSize' is zero. You see I made that many-to-many mapping fetch=EAGER.





On Thu, May 30, 2013 at 7:51 AM, jamesssss <jamesssss@xxxxxxxxx> wrote:
You XML is not correct,

>     <no-sql dataFormat="DataFormatType.MAPPED" />

This should be,

    <no-sql data-format="MAPPED" />

Refer to the EclipseLink ORM schema,

http://wiki.eclipse.org/EclipseLink/XSDs

To validate your ORM at runtime set,

"eclipselink.orm.validate.schema"="true"

in your persistence.xml

(or validate your XML inside your IDE such as Eclipse's XML editor)




--
View this message in context: http://eclipse.1072660.n5.nabble.com/Example-using-EclipseLink-MongoDB-XML-Mappings-tp160249p160298.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top