Package org.hibernate.ogm.backendtck.inheritance

Source Code of org.hibernate.ogm.backendtck.inheritance.JPAPolymorphicFindTest

/*
* Hibernate OGM, Domain model persistence for NoSQL datastores
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.ogm.backendtck.inheritance;

import static org.fest.assertions.Assertions.assertThat;
import static org.hibernate.ogm.utils.TestHelper.dropSchemaAndDatabase;
import static org.hibernate.ogm.utils.jpa.JpaTestCase.extractJBossTransactionManager;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.transaction.TransactionManager;

import org.hibernate.ogm.backendtck.simpleentity.Hero;
import org.hibernate.ogm.backendtck.simpleentity.SuperHero;
import org.hibernate.ogm.utils.PackagingRule;
import org.hibernate.ogm.utils.TestHelper;
import org.junit.Rule;
import org.junit.Test;

/**
* @author Jonathan Wood <jonathanshawwood@gmail.com>
*/
public class JPAPolymorphicFindTest {

  @Rule
  public PackagingRule packaging = new PackagingRule( "persistencexml/jpajtastandalone.xml", Hero.class, SuperHero.class );

  @Test
  public void testJPAPolymorphicFind() throws Exception {

    final EntityManagerFactory emf = Persistence.createEntityManagerFactory( "jpajtastandalone",
        TestHelper.getEnvironmentProperties() );

    TransactionManager transactionManager = extractJBossTransactionManager( emf );

    transactionManager.begin();
    final EntityManager em = emf.createEntityManager();
    Hero h = new Hero();
    h.setName( "Spartacus" );
    em.persist( h );
    SuperHero sh = new SuperHero();
    sh.setName( "Batman" );
    sh.setSpecialPower( "Technology and samurai techniques" );
    em.persist( sh );
    transactionManager.commit();

    em.clear();

    transactionManager.begin();
    Hero lh = em.find( Hero.class, h.getName() );
    assertThat( lh ).isNotNull();
    assertThat( lh ).isInstanceOf( Hero.class );
    Hero lsh = em.find( Hero.class, sh.getName() );
    assertThat( lsh ).isNotNull();
    assertThat( lsh ).isInstanceOf( SuperHero.class );
    em.remove( lh );
    em.remove( lsh );

    transactionManager.commit();

    em.close();

    dropSchemaAndDatabase( emf );
    emf.close();
  }

}
TOP

Related Classes of org.hibernate.ogm.backendtck.inheritance.JPAPolymorphicFindTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.