Package org.mongodb.morphia.testmodel

Examples of org.mongodb.morphia.testmodel.RecursiveChild



    @Test(expected = MappingException.class)
    public void testReferenceWithoutIdValue() throws Exception {
        final RecursiveParent parent = new RecursiveParent();
        final RecursiveChild child = new RecursiveChild();
        child.setId(null);
        parent.setChild(child);
        getDs().save(parent);

    }
View Full Code Here


        final RecursiveParent parent = new RecursiveParent();
        final DBObject parentDbObj = getMorphia().toDBObject(parent);
        stuff.save(parentDbObj);

        final RecursiveChild child = new RecursiveChild();
        final DBObject childDbObj = getMorphia().toDBObject(child);
        stuff.save(childDbObj);

        final RecursiveParent parentLoaded = getMorphia().fromDBObject(RecursiveParent.class,
                                                                       stuff.findOne(new BasicDBObject(Mapper.ID_KEY,
                                                                                                       parentDbObj.get(Mapper.ID_KEY))),
                                                                       new DefaultEntityCache());
        final RecursiveChild childLoaded = getMorphia().fromDBObject(RecursiveChild.class,
                                                                     stuff.findOne(new BasicDBObject(Mapper.ID_KEY,
                                                                                                     childDbObj.get(Mapper.ID_KEY))),
                                                                     new DefaultEntityCache());

        parentLoaded.setChild(childLoaded);
        childLoaded.setParent(parentLoaded);

        stuff.save(getMorphia().toDBObject(parentLoaded));
        stuff.save(getMorphia().toDBObject(childLoaded));

        final RecursiveParent finalParentLoaded = getMorphia().fromDBObject(RecursiveParent.class,
                                                                            stuff.findOne(new BasicDBObject(Mapper.ID_KEY,
                                                                                                            parentDbObj.get(Mapper
                                                                                                                                .ID_KEY))),
                                                                            new DefaultEntityCache());
        final RecursiveChild finalChildLoaded = getMorphia().fromDBObject(RecursiveChild.class,
                                                                          stuff.findOne(new BasicDBObject(Mapper.ID_KEY,
                                                                                                          childDbObj.get(Mapper.ID_KEY))),
                                                                          new DefaultEntityCache());

        assertNotNull(finalParentLoaded.getChild());
        assertNotNull(finalChildLoaded.getParent());
    }
View Full Code Here

TOP

Related Classes of org.mongodb.morphia.testmodel.RecursiveChild

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.