Creating collections

This is a nice easy one, just use the @MakeCollection annotation. Its up to you to ensure that an object created with @MakeCollection is actually a collection in the sense that it has a corresponding @ChildrenOf method. If not ... strange things might happen.

    @MakeCollection
    public Musician createAndSaveMusician(MusiciansController root, String newName) {
        Transaction tx = SessionManager.session().beginTransaction();
        Musician m = new Musician();
        m.setCreatedDate(new Date());
        m.setModifiedDate(new Date());
        m.setName(newName);
        SessionManager.session().save(m);
        SessionManager.session().flush();
        tx.commit();
        return m;
    }

 

See MusiciansController for full source code