// Start a unit of work (manually, no container)
getUserTransaction().begin();
EntityManager em = getEntityManagerFactory().createEntityManager();
// Prepare the DAOs (manually, no Seam)
ItemDAO itemDAO = new ItemDAOBean();
((GenericEJB3DAO) itemDAO).setEntityManager(em);
UserDAO userDAO = new UserDAOBean();
((GenericEJB3DAO) userDAO).setEntityManager(em);
// Prepare a user object
User user = userDAO.findById(1l, false);
// Make a new auction item persistent
Calendar startDate = GregorianCalendar.getInstance();
Calendar endDate = GregorianCalendar.getInstance();
endDate.add(Calendar.DAY_OF_YEAR, 3);
MonetaryAmount initialPrice =
new MonetaryAmount(new BigDecimal(123), Currency.getInstance("USD"));
MonetaryAmount reservePrice =
new MonetaryAmount(new BigDecimal(333), Currency.getInstance("USD"));
Item newItem =
new Item( "Testitem", "Test Description", user,
initialPrice, reservePrice,
startDate.getTime(), endDate.getTime() );
// Don't forget to take the return value, this is basically a merge()
newItem = itemDAO.makePersistent(newItem);
// End the unit of work
getUserTransaction().commit();
em.close();