This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception - when create a new factory by Persistence class  RSS feed

avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I need to create factory in run time because i dont know the shema names.
A new schema is allocated to the user after he register to the system.

I am working in Jboss 4.2.

I have a stateless session bean with the following method:

public void createEntityManagerFactoryWithPersistenceAPI() {
try {
Hotel h = new Hotel("Bla","Bla");
//****************** Map configuration
Map configOverrides = new HashMap();
configOverrides.put("javax.persistence.jtaDataSource", "java:/TestDS");
configOverrides.put("", "create");
configOverrides.put("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
configOverrides.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");

configOverrides.put("hibernate.default_schema", "Test");

EntityManagerFactory programmaticEmf =
new InitialContext().rebind("java:/TestEMF", programmaticEmf);
}catch(Exception e){


I get an exception when i try to create the factory:
19:14:49,492 ERROR [STDERR] javax.persistence.PersistenceException: org.hibernate.HibernateException: The chosen transaction strategy requir
es access to the JTA TransactionManager
19:14:49,492 ERROR [STDERR] at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(
19:14:49,492 ERROR [STDERR] at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(
19:14:49,492 ERROR [STDERR] at javax.persistence.Persistence.createEntityManagerFactory(
19:14:49,492 ERROR [STDERR] at service.impl.HotelServiceBean.createEntityManagerFactoryWithPersistenceAPI(

if i set to the following to the properties:
configOverrides.put("javax.persistence.transactionType", "RESOURCE_LOCAL");

the factory is created, but when i try to use it i get an exception:
18:36:54,138 ERROR [JDBCTransaction] JDBC commit failed

java.sql.SQLException: You cannot commit during a managed transaction!

at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.jdbcCommit(

My DS:
<!-- should only be used on drivers after 3.22.1 with "ping" support
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
<!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>

My persistence.xml file:
<persistence-unit name="Demo">
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->

Thank you!!!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!