diff --git a/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/SFSBHibernateSessionFactory.java b/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/SFSBHibernateSessionFactory.java new file mode 100644 index 0000000000..762fb61667 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/SFSBHibernateSessionFactory.java @@ -0,0 +1,47 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.wf.ddl; + +/** + * @author Andrea Boriero + */ + +import javax.ejb.Stateful; +import javax.ejb.TransactionAttribute; +import javax.ejb.TransactionAttributeType; +import javax.ejb.TransactionManagement; +import javax.ejb.TransactionManagementType; + +import org.hibernate.SessionFactory; +import org.hibernate.cfg.Configuration; + + +@Stateful +@TransactionManagement(TransactionManagementType.CONTAINER) +public class SFSBHibernateSessionFactory { + + private static SessionFactory sessionFactory; + + @TransactionAttribute(TransactionAttributeType.NEVER) + public void setupConfig() { + try { + Configuration configuration = new Configuration(); + configuration = configuration.configure( "hibernate.cfg.xml" ); + configuration.addAnnotatedClass( WildFlyDdlEntity.class ); + + sessionFactory = configuration.buildSessionFactory(); + } + catch (Throwable ex) { + System.err.println( "Initial SessionFactory creation failed." + ex ); + throw new ExceptionInInitializerError( ex ); + } + } + + public void cleanup() { + sessionFactory.close(); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/WildFlyHibernateDdlTest.java b/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/WildFlyHibernateDdlTest.java new file mode 100644 index 0000000000..8233432c36 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/WildFlyHibernateDdlTest.java @@ -0,0 +1,87 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.wf.ddl; + +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.hibernate.testing.TestForIssue; + +/** + * @author Andrea Boriero + */ +@RunWith(Arquillian.class) +@TestForIssue(jiraKey = "HHH-11024") +public class WildFlyHibernateDdlTest { + + public static final String ARCHIVE_NAME = "WildFlyHibernateDdlTest"; + + public static final String hibernate_cfg = "" + + "" + + "" + "true" + + "true" + + "create-drop" + + "java:jboss/datasources/ExampleDS" + + "JBossAppServerJtaPlatform.class" + + "true" + + ""; + + @ArquillianResource + private static InitialContext iniCtx; + + @BeforeClass + public static void beforeClass() throws NamingException { + iniCtx = new InitialContext(); + } + + @Deployment + public static WebArchive deploy() throws Exception { + final WebArchive war = ShrinkWrap.create( WebArchive.class, ARCHIVE_NAME + ".war" ) + .setManifest( "org/hibernate/test/wf/ddl/manifest.mf" ) + .addClasses( WildFlyDdlEntity.class ) + .addAsResource( new StringAsset( hibernate_cfg ), "hibernate.cfg.xml" ) + .addClasses( SFSBHibernateSessionFactory.class ) + .addClasses( WildFlyHibernateDdlTest.class ); + return war; + } + + @Test + public void testCreateThenDrop() throws Exception { + final SFSBHibernateSessionFactory sfsb = lookup( + "SFSBHibernateSessionFactory", + SFSBHibernateSessionFactory.class + ); + try { + sfsb.setupConfig(); + } + finally { + sfsb.cleanup(); + } + } + + private static T lookup(String beanName, Class interfaceType) throws NamingException { + try { + return interfaceType.cast( iniCtx.lookup( "java:global/" + ARCHIVE_NAME + "/" + beanName + "!" + + interfaceType.getName() ) ); + } + catch (NamingException e) { + throw e; + } + } +}