/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.ejb3.test.regression;

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * comment
 *
 * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
 */
@Stateless
@Remote(AccountDAO.class)
public class AccountDAOBean implements AccountDAO
{
   @PersistenceContext private EntityManager em;

   public long createAccount()
   {
      Account account = new Account();
      em.persist(account);
      AccountName name1 = new AccountName();
      name1.setAccount(account);
      account.getNames().add(name1);
      AccountNamePK pk = new AccountNamePK(account.getId(), "US");
      name1.setPk(pk);
      em.persist(name1);

      AccountName name2 = new AccountName();
      name2.setAccount(account);
      account.getNames().add(name2);
      AccountNamePK pk2 = new AccountNamePK(account.getId(), "FRA");
      name2.setPk(pk2);
      em.persist(name2);
      return account.getId();
   }

   public Account findAccount(long id)
   {
      return em.find(Account.class, id);
   }
}
