Hi everybody!
I get a
Code:
[org.hibernate.tool.hbm2ddl.SchemaExport] schema export unsuccessful
java.sql.SQLException: You cannot commit during a managed transaction!
when using Hibernate on a DS stored in a JBoss JNDI tree.
Now, I've been reading some of the docu and forum entries and I came to understand that I need to configure
Code:
<property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
in a JBoss-managed environment. I also learned that this exceptions occurs inevitably when I am trying to commit a transaction while I am executing a container managed transaction. However, I am not in a EJB bean, but in a portlet. So, in my mind the question should be: Why is it a (container) managed connection? How can I configure it to be a bean managed connection?
Any help, comment or link (to a web resource with the solution of more footage on the problem) is very welcome.
Sincerely
PI
Hibernate version: 3.0.5
Mapping documents:Code:
<hibernate-configuration>
<session-factory>
<property name="show_sql">false</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
<mapping resource.../>
</session-factory>
</hibernate-configuration>
Note: the JNDI DS Name and the Dialect are specified via portlet init parameters and manually added to the configuration prior to creating the SessionFactory.
Configuration of DS in JBoss
<?xml version="1.0" encoding="UTF-8"?>
Code:
<datasources>
<local-tx-datasource>
<jndi-name>PreferencesDS</jndi-name>
<connection-url>jdbc:hsqldb:${jboss.server.data.dir}${/}hypersonic${/}preferencesDB</connection-url>
<driver-class>org.hsqldb.jdbcDriver</driver-class>
<user-name>sa</user-name>
<password></password>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
<idle-timeout-minutes>0</idle-timeout-minutes>
<track-statements/>
<metadata>
<type-mapping>Hypersonic SQL</type-mapping>
</metadata>
<depends>jboss:service=Hypersonic,database=preferencesDB</depends>
</local-tx-datasource>
<mbean code="org.jboss.jdbc.HypersonicDatabase"
name="jboss:service=Hypersonic,database=preferencesDB">
<attribute name="Database">preferencesDB</attribute>
<attribute name="InProcessMode">true</attribute>
</mbean>
</datasources>
Code between sessionFactory.openSession() and session.close():n/a (happens already in HBM2DDL during the creation of the session factory)
Full stack trace of any exception that occurs:Code:
2005-09-15 12:39:54,968 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] Running hbm2ddl schema export
2005-09-15 12:39:54,968 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] exporting generated schema to database
2005-09-15 12:39:54,968 INFO [org.hibernate.util.NamingHelper] JNDI InitialContext properties:{}
2005-09-15 12:39:54,968 INFO [org.hibernate.connection.DatasourceConnectionProvider] Using datasource: java:PreferencesDS
2005-09-15 12:39:54,968 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] schema export unsuccessful
java.sql.SQLException: You cannot commit during a managed transaction!
at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:519)
at org.jboss.resource.adapter.jdbc.WrappedConnection.commit(WrappedConnection.java:451)
at org.hibernate.tool.hbm2ddl.SchemaExport$ProviderConnectionHelper.getConnection(SchemaExport.java:434)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:130)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:99)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:264)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
Note: omitted the trail of the stack trace that is all about JBoss calling the portal, then my portlet, then my portlet calling Hibernate
Name and version of the database you are using:
HSQLDB (not sure about the version; if there is HSQLDB shipped with JBossAS Portal release (from July/August), it's this one)