// Merge Test:Have a class(TelephoneNumber) that uses a composite primary key (defined in
  // annotations) and define a 1-M (BeerConsumer->TelephoneNumber) for it in XML
  // Setup Relationship
  public void testOneToManyRelationships() {
    EntityManager em = createEntityManager();
    try {
      beginTransaction(em);

      BeerConsumer consumer = new BeerConsumer();
      consumer.setName("Joe Black");

      TelephoneNumber homeNumber = new TelephoneNumber();
      homeNumber.setAreaCode("555");
      homeNumber.setType("Home");
      homeNumber.setNumber("123-1234");

      TelephoneNumber workNumber = new TelephoneNumber();
      workNumber.setAreaCode("555");
      workNumber.setType("Work");
      workNumber.setNumber("987-9876");

      consumer.addTelephoneNumber(homeNumber);
      consumer.addTelephoneNumber(workNumber);
      em.persist(consumer);
      beerConsumerId = consumer.getId();

      commitTransaction(em);
    } catch (RuntimeException e) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }
      throw e;
    }
  }
  public void testCoronaBeerConsumer() {
    EntityManager em = createEntityManager();
    beginTransaction(em);

    BeerConsumer initialBC = new BeerConsumer();
    int beerConsumerId = 0;

    try {
      Corona corona1 = new Corona();
      corona1.setAlcoholContent(5.3);
      CoronaTag coronaTag1 = new CoronaTag();
      coronaTag1.setCode("0A");
      coronaTag1.setNumber(789);

      Corona corona2 = new Corona();
      corona2.setAlcoholContent(5.3);
      CoronaTag coronaTag2 = new CoronaTag();
      coronaTag2.setCode("BX");
      coronaTag2.setNumber(521);

      Corona corona3 = new Corona();
      corona3.setAlcoholContent(5.3);
      CoronaTag coronaTag3 = new CoronaTag();
      coronaTag3.setCode("UY");
      coronaTag3.setNumber(429);

      initialBC.setName("Corona Consumer");
      initialBC.addCoronaBeerToConsume(corona1, coronaTag1);
      initialBC.addCoronaBeerToConsume(corona2, coronaTag2);
      initialBC.addCoronaBeerToConsume(corona3, coronaTag3);

      em.persist(initialBC);
      beerConsumerId = initialBC.getId();

      commitTransaction(em);
    } catch (RuntimeException e) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }

      closeEntityManager(em);
      fail("An exception was caught during create operation: [" + e.getMessage() + "]");
    }

    closeEntityManager(em);

    clearCache();
    em = createEntityManager();
    BeerConsumer refreshedBC = em.find(BeerConsumer.class, beerConsumerId);
    assertTrue(
        "The beer consumer read back did not match the original",
        getServerSession().compareObjects(initialBC, refreshedBC));
  }
  public void testBecksBeerConsumer() {
    EntityManager em = createEntityManager();
    beginTransaction(em);

    BeerConsumer initialBC = new BeerConsumer();
    int beerConsumerId = 0;

    try {
      Becks becks1 = new Becks();
      becks1.setAlcoholContent(5.1);
      BecksTag becksTag1 = new BecksTag();
      becksTag1.setCallNumber("0A.789");
      em.persist(becksTag1);

      Becks becks2 = new Becks();
      becks2.setAlcoholContent(5.1);
      BecksTag becksTag2 = new BecksTag();
      becksTag2.setCallNumber("BX.521");
      em.persist(becksTag2);

      Becks becks3 = new Becks();
      becks3.setAlcoholContent(5.1);
      BecksTag becksTag3 = new BecksTag();
      becksTag3.setCallNumber("UY.429");
      em.persist(becksTag3);

      initialBC.setName("Becks Consumer");
      initialBC.addBecksBeerToConsume(becks1, becksTag1);
      initialBC.addBecksBeerToConsume(becks2, becksTag2);
      initialBC.addBecksBeerToConsume(becks3, becksTag3);

      em.persist(initialBC);
      beerConsumerId = initialBC.getId();

      commitTransaction(em);
    } catch (RuntimeException e) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }

      closeEntityManager(em);
      fail("An exception was caught during create operation: [" + e.getMessage() + "]");
    }

    closeEntityManager(em);

    clearCache();
    em = createEntityManager();
    BeerConsumer refreshedBC = em.find(BeerConsumer.class, beerConsumerId);
    assertTrue(
        "The beer consumer read back did not match the original",
        getServerSession().compareObjects(initialBC, refreshedBC));
  }
  public void testHeinekenBeerConsumer() {
    EntityManager em = createEntityManager();
    beginTransaction(em);

    BeerConsumer initialBC = new BeerConsumer();
    int beerConsumerId = 0;

    try {
      Heineken heineken1 = new Heineken();
      heineken1.setAlcoholContent(5.0);

      Heineken heineken2 = new Heineken();
      heineken2.setAlcoholContent(5.0);

      Heineken heineken3 = new Heineken();
      heineken3.setAlcoholContent(5.0);

      initialBC.setName("Heineken Consumer");
      Calendar cal = Calendar.getInstance();
      cal.set(2008, 12, 12);
      initialBC.addHeinekenBeerToConsume(heineken1, cal.getTime());
      cal.set(2009, 1, 1);
      initialBC.addHeinekenBeerToConsume(heineken2, cal.getTime());
      cal.set(2009, 2, 2);
      initialBC.addHeinekenBeerToConsume(heineken3, cal.getTime());

      em.persist(initialBC);
      beerConsumerId = initialBC.getId();

      commitTransaction(em);
    } catch (RuntimeException e) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }

      closeEntityManager(em);
      fail("An exception was caught during create operation: [" + e.getMessage() + "]");
    }

    closeEntityManager(em);

    clearCache();
    em = createEntityManager();
    BeerConsumer refreshedBC = em.find(BeerConsumer.class, beerConsumerId);
    assertTrue(
        "The beer consumer read back did not match the original",
        getServerSession().compareObjects(initialBC, refreshedBC));
  }
 public void testReadBeerConsumer() {
   BeerConsumer consumer = createEntityManager().find(BeerConsumer.class, beerConsumerId);
   assertTrue("Error reading BeerConsumer", consumer.getId() == beerConsumerId);
 }
  public void testCreateBeerConsumer() {
    EntityManager em = createEntityManager();
    try {
      beginTransaction(em);

      BeerConsumer consumer = new BeerConsumer();
      consumer.setName("Joe Black");

      em.persist(consumer);
      beerConsumerId = consumer.getId();

      Alpine alpine1 = new Alpine();
      alpine1.setAlcoholContent(5.0);
      alpine1.setBeerConsumer(consumer);
      alpine1.setBestBeforeDate(new Date(System.currentTimeMillis() + 10000000));
      em.persist(alpine1);

      Canadian canadian1 = new Canadian();
      canadian1.setAlcoholContent(5.5);
      canadian1.setBeerConsumer(consumer);
      canadian1.setBornOnDate(new Date(System.currentTimeMillis() - 30000000));
      em.persist(canadian1);

      Canadian canadian2 = new Canadian();
      canadian2.setAlcoholContent(5.0);
      canadian2.setBeerConsumer(consumer);
      canadian2.setBornOnDate(new Date(System.currentTimeMillis() - 23000000));
      em.persist(canadian2);

      /*
      TelephoneNumber homeNumber = new TelephoneNumber();
      homeNumber.setAreaCode("555");
      homeNumber.setType("Home");
      homeNumber.setNumber("123-1234");
      getEntityManager().persist(homeNumber);

      TelephoneNumber workNumber = new TelephoneNumber();
      workNumber.setAreaCode("555");
      workNumber.setType("Work");
      workNumber.setNumber("987-9876");
      getEntityManager().persist(workNumber);
      */

      Certification cert1 = new Certification();
      cert1.setDescription("Value brand beer consumption certified");
      cert1.setBeerConsumer(consumer);
      em.persist(cert1);

      Certification cert2 = new Certification();
      cert2.setDescription("Premium brand beer consumption certified");
      cert2.setBeerConsumer(consumer);
      em.persist(cert2);

      em.persist(consumer);
      commitTransaction(em);
    } catch (RuntimeException e) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }
      throw e;
    }
  }