org.hibernate.tool.hbm2ddl.SchemaUpdate无法获取数据库元数据:java.sql.SQLException:您无法在托管事务期间设置自动提交

时间:2012-01-12 10:45:36

标签: hibernate jboss6.x hbm2ddl

我遇到Hibernate 3.6架构更新问题。我正在使用Jboss 6,我可以使hibernate.hbm2ddl.auto属性工作。换句话说,架构不会更新。我还在使用EJB2。从Jboss4迁移到6并将hibernate 3.1迁移到3.6时会出现此问题,但是我不确定它是否是实际原因。有没有人记得面对这个问题?所有帮助表示赞赏:)

的hibernate.cfg.xml

<!-- Datasource to use -->
<property name="hibernate.connection.datasource">
    java:/xxxDS
</property>

<!-- Dialect -->
<property name="hibernate.dialect">
    <!--  org.hibernate.dialect.SQLServerDialect-->
    xxx.server.util.xxxMSSQLServerDialect
</property>

<property name="hibernate.cache.provider_class">
    org.hibernate.cache.HashtableCacheProvider
</property>

<property name="hibernate.current_session_context_class">
    jta
</property>

<property name="hibernate.transaction.manager_lookup_class">
    org.hibernate.transaction.JBossTransactionManagerLookup
</property>

<property name="hibernate.transaction.factory_class">
    org.hibernate.transaction.JTATransactionFactory
</property>

<!-- 
    <property name="jta.UserTransaction">
    java:comp/UserTransaction
    </property> -->
<property name="hibernate.show_sql">false</property>
<property name="hibernate.hbm2ddl.auto">update</property>

<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.transaction.flush_before_completion">
    true
</property>
<property name="hibernate.transaction.auto_close_session">
    true
</property>

    .
    .
    .

Jboss log

  09:08:21,349 INFO  [org.hibernate.cfg.SettingsFactory] Database ->
   name : Microsoft SQL Server
version : 10.50.1617
  major : 10
  minor : 50
09:08:21,350 INFO  [org.hibernate.cfg.SettingsFactory] Driver ->
   name : Microsoft SQL Server 2005 JDBC Driver
version : 1.2.2828.100
  major : 1
  minor : 2
09:08:21,350 INFO  [org.hibernate.transaction.TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.JTATransactionFactory
09:08:21,352 INFO  [org.hibernate.util.NamingHelper] JNDI InitialContext properties:{}
09:08:21,352 INFO  [org.hibernate.transaction.TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
09:08:21,356 INFO  [org.hibernate.transaction.TransactionManagerLookupFactory] instantiated TransactionManagerLookup
09:08:21,356 INFO  [org.hibernate.transaction.TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
09:08:21,356 INFO  [org.hibernate.transaction.TransactionManagerLookupFactory] instantiated TransactionManagerLookup
09:08:21,356 INFO  [org.hibernate.cfg.SettingsFactory] Automatic flush during beforeCompletion(): enabled
09:08:21,357 INFO  [org.hibernate.cfg.SettingsFactory] Automatic session close at end of transaction: enabled
09:08:21,357 INFO  [org.hibernate.cfg.SettingsFactory] Scrollable result sets: enabled
09:08:21,357 INFO  [org.hibernate.cfg.SettingsFactory] JDBC3 getGeneratedKeys(): enabled
09:08:21,357 INFO  [org.hibernate.cfg.SettingsFactory] Connection release mode: auto
09:08:21,357 INFO  [org.hibernate.cfg.SettingsFactory] Default batch fetch size: 1
09:08:21,357 INFO  [org.hibernate.cfg.SettingsFactory] Generate SQL with comments: disabled
09:08:21,357 INFO  [org.hibernate.cfg.SettingsFactory] Order SQL updates by primary key: disabled
09:08:21,357 INFO  [org.hibernate.cfg.SettingsFactory] Order SQL inserts for batching: disabled
09:08:21,357 INFO  [org.hibernate.cfg.SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
09:08:21,357 INFO  [org.hibernate.hql.ast.ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
09:08:21,358 INFO  [org.hibernate.cfg.SettingsFactory] Query language substitutions: {}
09:08:21,358 INFO  [org.hibernate.cfg.SettingsFactory] JPA-QL strict compliance: disabled
09:08:21,358 INFO  [org.hibernate.cfg.SettingsFactory] Second-level cache: enabled
09:08:21,358 INFO  [org.hibernate.cfg.SettingsFactory] Query cache: disabled
09:08:21,358 INFO  [org.hibernate.cfg.SettingsFactory] Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
09:08:21,358 INFO  [org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge] Cache provider: org.hibernate.cache.HashtableCacheProvider
09:08:21,358 INFO  [org.hibernate.cfg.SettingsFactory] Optimize cache for minimal puts: disabled
09:08:21,358 INFO  [org.hibernate.cfg.SettingsFactory] Structured second-level cache entries: disabled
09:08:21,358 INFO  [org.hibernate.cfg.SettingsFactory] Statistics: disabled
09:08:21,358 INFO  [org.hibernate.cfg.SettingsFactory] Deleted entity synthetic identifier rollback: disabled
09:08:21,358 INFO  [org.hibernate.cfg.SettingsFactory] Default entity-mode: pojo
09:08:21,359 INFO  [org.hibernate.cfg.SettingsFactory] Named query checking : enabled
09:08:21,359 INFO  [org.hibernate.cfg.SettingsFactory] Check Nullability in Core (should be disabled when Bean Validation is on): disabled
09:08:21,404 INFO  [org.hibernate.impl.SessionFactoryImpl] building session factory
09:08:21,411 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [characters_clob] overrides previous : org.hibernate.type.PrimitiveCharacterArrayClobType@1f2f29d
09:08:21,411 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [wrapper_characters_clob] overrides previous : org.hibernate.type.CharacterArrayClobType@116630b
09:08:21,412 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [materialized_clob] overrides previous : org.hibernate.type.MaterializedClobType@c07b39
09:08:21,412 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [clob] overrides previous : org.hibernate.type.ClobType@d9f329
09:08:21,412 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [java.sql.Clob] overrides previous : org.hibernate.type.ClobType@d9f329
09:08:21,412 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [blob] overrides previous : org.hibernate.type.BlobType@eb3965
09:08:21,412 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [java.sql.Blob] overrides previous : org.hibernate.type.BlobType@eb3965
09:08:21,413 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [materialized_blob] overrides previous : org.hibernate.type.MaterializedBlobType@105320e
09:08:21,413 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [wrapper_materialized_blob] overrides previous : org.hibernate.type.WrappedMaterializedBlobType@193bcf
09:08:22,452 INFO  [org.hibernate.impl.SessionFactoryObjectFactory] Factory name: java:/hibernate/SMBPlannerSessionFactory
09:08:22,452 INFO  [org.hibernate.util.NamingHelper] JNDI InitialContext properties:{}
09:08:22,454 INFO  [org.hibernate.impl.SessionFactoryObjectFactory] Bound factory to JNDI name: java:/hibernate/SMBPlannerSessionFactory
09:08:22,487 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] Running hbm2ddl schema update
09:08:22,487 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] fetching database metadata
10:40:08,124 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] could not complete schema update: java.sql.SQLException: You cannot set autocommit during a managed transaction!
    at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.setJdbcAutoCommit(BaseWrapperManagedConnection.java:600) [:6.1.0.Final]
    at org.jboss.resource.adapter.jdbc.WrappedConnection.setAutoCommit(WrappedConnection.java:468) [:6.1.0.Final]
    at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:60) [:3.6.6.Final]
    at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:168) [:3.6.6.Final]
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:375) [:3.6.6.Final]
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872) [:3.6.6.Final]
    at xxxx.server.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:28) [:]
    at xxxx.server.util.HibernateUtil.<clinit>(HibernateUtil.java:11) [:]
    at xxxx.dao.PlDAOBase.getObjectsByCriteria(PlDAOBase.java:125) [:]
    at xxxx.server.manager.PlResourceManagerBase.getObjectsByCriteria(PlResourceManagerBase.java:114) [:]
    at xxxx.server.manager.GeneralManager.getApplicationParam(GeneralManager.java:141) [:]
    at xxxx.server.manager.SimulationManager.initParams(SimulationManager.java:95) [:]
    at xxxx.server.manager.SimulationManager.<init>(SimulationManager.java:68) [:]
    at xxxx.ejb.bean.PlSMBPlannerSessionBean.getReferences(PlSMBPlannerSessionBean.java:138) [:]
    at xxxx.ejb.beanxxxSessionBean.getApplicationParam(xxxSessionBean.java:4505) [:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_21]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_21]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_21]
    at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_21]
    at org.jboss.invocation.Invocation.performCall(Invocation.java:386) [:6.1.0.Final]
    at org.jboss.ejb.StatefulSessionContainer$ContainerInterceptor.invoke(StatefulSessionContainer.java:620) [:6.1.0.Final]
    at org.jboss.ejb.plugins.StatefulSessionSecurityInterceptor.invoke(StatefulSessionSecurityInterceptor.java:84) [:6.1.0.Final]
    at org.jboss.ejb.plugins.SecurityInterceptor.process(SecurityInterceptor.java:228) [:6.1.0.Final]
    at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:211) [:6.1.0.Final]
    at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:156) [:6.1.0.Final]
    at org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor.invoke(StatefulSessionInstanceInterceptor.java:348) [:6.1.0.Final]
    at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:63) [:6.1.0.Final]
    at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:121) [:6.1.0.Final]
    at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:350) [:6.1.0.Final]
    at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:181) [:6.1.0.Final]
    at org.jboss.ejb.plugins.security.PreSecurityInterceptor.process(PreSecurityInterceptor.java:100) [:6.1.0.Final]
    at org.jboss.ejb.plugins.security.PreSecurityInterceptor.invoke(PreSecurityInterceptor.java:84) [:6.1.0.Final]
    at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:205) [:6.1.0.Final]
    at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:138) [:6.1.0.Final]
    at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:650) [:6.1.0.Final]
    at org.jboss.ejb.Container.invoke(Container.java:1072) [:6.1.0.Final]

。 。

的persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
  <persistence-unit name="smbplanner_pu">
    <description>EntityManagerFactory for smbplanner</description>

<jta-data-source>java:/smbplannerDS</jta-data-source>
<properties>
    <property name="hibernate.hbm2ddl.auto" value="update"/>
    <property name="jboss.entity.manager.factory.jndi.name" value="java:/hibernate/xxxSessionFactory"/>     
    <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect"/>
    <property name="CacheProviderClass" value="org.hibernate.cache.HashtableCacheProvider"/>
    <property name="ShowSqlEnabled" value="false"/>
</properties>

   </persistence-unit>
 </persistence>

0 个答案:

没有答案