DMItem item1 = new DMItem();
DMItem item2 = new DMItem();
item1.setName("item-1"); item1.setPrice(100.0);
item2.setName("item-2"); item2.setPrice(200.0);
DMCustomerInventory inventory1 = new DMCustomerInventory();
DMCustomerInventory inventory2 = new DMCustomerInventory();
inventory1.setItem(item1); inventory1.setQuantity(10);
inventory2.setItem(item2); inventory2.setQuantity(20);
DMCustomer customer = new DMCustomer();
customer.setFirstName("Detached"); customer.setLastName("Customer");
customer.setCustomerInventories(Arrays.asList(
new DMCustomerInventory[]{inventory1,inventory2}));
inventory1.setCustomer(customer);
inventory2.setCustomer(customer);
em.getTransaction().begin();
em.persist(customer);
em.getTransaction().commit();
em.clear();