-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Exception - when create a new factory by Persistence class
PostPosted: Wed Jun 06, 2007 1:12 pm 
Regular
Regular

Joined: Wed May 02, 2007 2:42 pm
Posts: 101
Hey,

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:

Code:
   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("hibernate.hbm2ddl.auto", "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 =
             Persistence.createEntityManagerFactory("Demo",configOverrides);
               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(Ejb3Configuration.java:720)
19:14:49,492 ERROR [STDERR] at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
19:14:49,492 ERROR [STDERR] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
19:14:49,492 ERROR [STDERR] at service.impl.HotelServiceBean.createEntityManagerFactoryWithPersistenceAPI(HotelServiceBean.java:83)


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(BaseWrapperManagedConnection.java:543)



My DS:
<datasources>
<local-tx-datasource>
<jndi-name>TestDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password>1234</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<!-- should only be used on drivers after 3.22.1 with "ping" support
<valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
-->
<!-- 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>
<persistence-unit name="Demo">
<jta-data-source>java:/InsiteDS</jta-data-source>
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
</persistence>
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>


Thank you!!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 9:42 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you need to define
Code:
hibernate.transaction.manager_lookup_class =
    org.hibernate.transaction.JBossTransactionManagerLookup

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Thank you!!!!!!!!!!!!!!!!!!!!!!!!!
PostPosted: Thu Jun 07, 2007 10:31 am 
Regular
Regular

Joined: Wed May 02, 2007 2:42 pm
Posts: 101
Now i can create for each user new schema and new factory without the need to declare on it in the persistence.xml and without the need to create DS in run time for each schema that i created.

Thank you.

and again - Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.