使用: Jboss 7.1.1、Hibernate 3.6.9、Spring 3.0.1。
Spring Transaction Manager からの切り替えを試みました。
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
Jboss トランザクション マネージャーへ:
<!-- search for transaction managers -->
<tx:jta-transaction-manager/>
org.springframework.orm.jpa.JpaTransactionManagerを使用するとすべて正常に動作しますが、「transactionManager」Bean を削除して「」を追加すると、次のエラーが発生します。
javax.persistence.TransactionRequiredException: no transaction is in progress
サーバーログで次のことを見つけました。
08:40:58,382 INFO [org.hibernate.transaction.TransactionFactoryFactory] (MSC service
thread 1-1) Using default transaction strategy (direct JDBC transactions)
08:40:58,383 INFO [org.hibernate.transaction.TransactionManagerLookupFactory] (MSC
service thread 1-1) No TransactionManagerLookup configured (in JTA
environment, use of read-write or transactional second-level cache is not
recommended)
それはどういう意味ですか?私のアプリケーションは現在java:jboss/TransactionManagerを使用していますか? Jboss で何かを設定する必要がありますか?
applicationContext.xml スニペット:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="xxx" />
<property name="dataSource" ref="dataSource" />
<property name="persistenceXmlLocation" value="classpath*:META-
INF/persistence.xml" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform"
value="org.hibernate.dialect.SQLServerDialect" />
<property name="showSql" value="false" />
<property name="generateDdl" value="false" />
</bean>
</property>
</bean>
<tx:jta-transaction-manager/>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${database.jndi.path}" />
persistence.xml スニペット:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="xxx" transaction-type="RESOURCE_LOCAL">
<!-- a lot of <class>com.MyClass</class> -->
<properties>
<property name="jboss.as.jpa.managed" value="false"/>
<property name="hibernate.dialect"
value="org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect"/>
</properties>
</persistence-unit>
persitence.xml の "RESOURCE_LOCAL" が間違っているのではないでしょうか?
ドメイン.xml:
<datasource jta="true" jndi-name="java:jboss/datasources/myName" pool-name="myName" use-ccm="true">
<connection-url>jdbc:sqlserver://10.100.0.91:1433;databaseName=db;user=myUser;password=myPassword</connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<driver>mssql</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>20</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>myName</user-name>
<password>myPassword</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
--編集-- applicationContext.xml と persistence.xml を変更しました。
applicationContext.xml スニペット:
<jee:jndi-lookup id="my_unit" jndi-name="java:jboss/my_unit" />
<tx:jta-transaction-manager/>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${database.jndi.path}" />
</bean>
persistence.xml スニペット:
?xml version="1.0" encoding="UTF-8" standalone="no"?>
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<jta-data-source>java:jboss/datasources/wtb</jta-data-source>
<properties>
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup" />
<property name="hibernate.dialect"
value="org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect" />
</properties>
</persistence-unit>
デプロイ中に次の例外が発生します。
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: my_unit] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
... 3 more
Caused by: org.hibernate.HibernateException: Dialect class not found: org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:76)
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:64)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:176)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2270)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2266)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1735)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
... 9 more
Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect]
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:141)
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:73)
... 20 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.findClass(ClassLoaderServiceImpl.java:99)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306) [rt.jar:1.6.0_32]
at java.lang.ClassLoader.loadClass(ClassLoader.java:247) [rt.jar:1.6.0_32]
at
org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138)
... 21 more