SuperHero.class, HeroClub.class );
@Test
public void testJPAPolymorphicCollection() 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 );
HeroClub hc = new HeroClub();
hc.setName( "My hero club" );
hc.getMembers().add( h );
hc.getMembers().add( sh );
em.persist( hc );
transactionManager.commit();
em.clear();
transactionManager.begin();
HeroClub lhc = em.find( HeroClub.class, hc.getName() );
assertThat( lhc ).isNotNull();
Hero lh = lhc.getMembers().get( 0 );
assertThat( lh ).isNotNull();
assertThat( lh ).isInstanceOf( Hero.class );
Hero lsh = lhc.getMembers().get( 1 );
assertThat( lsh ).isNotNull();
assertThat( lsh ).isInstanceOf( SuperHero.class );
lhc.getMembers().clear();
em.remove( lh );
em.remove( lsh );
em.remove( lhc );
transactionManager.commit();
em.close();
dropSchemaAndDatabase( emf );
emf.close();
}