Search in sources :

Example 1 with PetroleumSupplier

use of org.datanucleus.samples.annotations.many_many.PetroleumSupplier in project tests by datanucleus.

the class RelationshipsTest method testManyToMany.

/**
 * Test of M-N relations.
 */
public void testManyToMany() {
    try {
        EntityManager em = getEM();
        EntityTransaction tx = em.getTransaction();
        try {
            tx.begin();
            PetroleumSupplier s = new PetroleumSupplier(101, "Esso");
            PetroleumCustomer c = new PetroleumCustomer(102, "Brians Fuels");
            s.getCustomers().add(c);
            c.getSuppliers().add(s);
            em.persist(c);
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Exception thrown while creating Customers and Suppliers");
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            em.close();
        }
    // TODO Retrieve the objects and check the persistence
    // TODO Do some updates
    } finally {
        clean(PetroleumSupplier.class);
        clean(PetroleumCustomer.class);
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) PetroleumSupplier(org.datanucleus.samples.annotations.many_many.PetroleumSupplier) EntityManager(javax.persistence.EntityManager) PetroleumCustomer(org.datanucleus.samples.annotations.many_many.PetroleumCustomer)

Aggregations

EntityManager (javax.persistence.EntityManager)1 EntityTransaction (javax.persistence.EntityTransaction)1 PetroleumCustomer (org.datanucleus.samples.annotations.many_many.PetroleumCustomer)1 PetroleumSupplier (org.datanucleus.samples.annotations.many_many.PetroleumSupplier)1