JPAプロバイダとしてHibernate 4.1でSpring Framework 3.1を使用していますが、完全に機能する設定ですが、Webアプリケーションを起動するたびに警告メッセージ:うまくSpring 3.1 + Hibernate 4.1 JPA、エンティティマネージャファクトリが2回登録されました
14:28:12,725 WARN pool-2-thread-12 internal.EntityManagerFactoryRegistry:80 - HHH000436: Entity manager factory name (something) is already registered. If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'
アプリケーションの機能が、それは私を気のような警告メッセージ、および検索し、微調整や実験の時間はどこに私をリードしていません。私は工場名を変更し、設定のチャンクを追加したり省略したりしてみました。 SpringまたはHibernateの何かが、エンティティマネージャファクトリを2回だけ初期化しているようです。
FYI、LocalContainerEntityManagerFactoryBeanのpackagesToScan機能を使用して、persistence.xmlファイルなしでエンティティマネージャを設定しています。
私は次のように私の春のコンテキストXMLを下に切り詰めて、問題が解決しました:完全性については
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<context:property-placeholder location="classpath:jdbc.properties"/>
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.nightsword.driverClassName}"/>
<property name="url" value="${jdbc.nightsword.url}"/>
<property name="username" value="${jdbc.nightsword.username}"/>
<property name="password" value="${jdbc.nightsword.password}"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="x.y"/>
</bean>
</beans>
を、ここにhibernate.propertiesです:
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.ejb.entitymanager_factory_name=something
そしてここでは、デバッグレベルのログを抜粋していますorg.springframework.ormとorg.hibernateの両方から出力されます。 EntityManagerFactoryが最初から登録されている方法は14:40:06,911で、その直後にLocalContainerEntityManagerFactoryBeanが最初からすべて開始されているように見えます。ハァッ。
INFO: Deploying web application archive /opt/local/share/java/tomcat7/webapps/nightsword.war
14:40:06,149 INFO pool-2-thread-13 jpa.LocalContainerEntityManagerFactoryBean:264 - Building JPA container EntityManagerFactory for persistence unit 'default'
14:40:06,219 DEBUG pool-2-thread-13 type.BasicTypeRegistry:143 - Adding type registration boolean -> [email protected]
...
14:40:06,882 DEBUG pool-2-thread-13 internal.SessionFactoryRegistry:62 - Initializing SessionFactoryRegistry : [email protected]
14:40:06,882 DEBUG pool-2-thread-13 internal.SessionFactoryRegistry:75 - Registering SessionFactory: a3219dd8-7d59-45ac-9a5a-0d13e38dbb04 (<unnamed>)
14:40:06,882 DEBUG pool-2-thread-13 internal.SessionFactoryRegistry:82 - Not binding SessionFactory to JNDI, no JNDI name configured
14:40:06,882 DEBUG pool-2-thread-13 internal.SessionFactoryImpl:487 - Instantiated session factory
14:40:06,882 DEBUG pool-2-thread-13 internal.SessionFactoryImpl:1119 - Checking 0 named HQL queries
14:40:06,883 DEBUG pool-2-thread-13 internal.SessionFactoryImpl:1142 - Checking 0 named SQL queries
14:40:06,887 DEBUG pool-2-thread-13 internal.StatisticsInitiator:110 - Statistics initialized [enabled=false]
14:40:06,910 DEBUG pool-2-thread-13 internal.EntityManagerFactoryRegistry:56 - Initializing EntityManagerFactoryRegistry : [email protected]
14:40:06,911 DEBUG pool-2-thread-13 internal.EntityManagerFactoryRegistry:66 - Registering EntityManagerFactory: something
14:40:06,967 INFO pool-2-thread-13 jpa.LocalContainerEntityManagerFactoryBean:264 - Building JPA container EntityManagerFactory for persistence unit 'default'
14:40:06,967 DEBUG pool-2-thread-13 type.BasicTypeRegistry:143 - Adding type registration boolean -> [email protected]
...
14:40:07,128 DEBUG pool-2-thread-13 internal.SessionFactoryRegistry:75 - Registering SessionFactory: 81a9b5a6-83aa-46ee-be68-d642e6fda584 (<unnamed>)
14:40:07,128 DEBUG pool-2-thread-13 internal.SessionFactoryRegistry:82 - Not binding SessionFactory to JNDI, no JNDI name configured
14:40:07,129 DEBUG pool-2-thread-13 internal.SessionFactoryImpl:487 - Instantiated session factory
14:40:07,129 DEBUG pool-2-thread-13 internal.SessionFactoryImpl:1119 - Checking 0 named HQL queries
14:40:07,129 DEBUG pool-2-thread-13 internal.SessionFactoryImpl:1142 - Checking 0 named SQL queries
14:40:07,129 DEBUG pool-2-thread-13 internal.StatisticsInitiator:110 - Statistics initialized [enabled=false]
14:40:07,130 DEBUG pool-2-thread-13 internal.EntityManagerFactoryRegistry:66 - Registering EntityManagerFactory: something
14:40:07,130 WARN pool-2-thread-13 internal.EntityManagerFactoryRegistry:80 - HHH000436: Entity manager factory name (something) is already registered. If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'
Spring Application Contextをどのように初期化していますか? web.xmlにorg.springframework.web.context.ContextLoaderListenerが宣言されていますか? Spring MVCを使用していますか?私は時々、他のアプリケーションをインポートするSpring MVC XML設定を見たことがあります。コンテキストXMLは、アプリケーションコンテキストとWebアプリケーションコンテキストで宣言されているため、いくつかのBeanをインスタンス化します。 – eolith
はい、私はあなたです。 DispatcherServletはContextLoaderListenerと同じコンテキストファイルをロードしていましたが、bamは2回読み込まれたBeanです。初心者のミス、どのように恥ずかしい!あなたが答えとしてあなたのコメントを言い換えたいのであれば、私はそれを受け入れてうれしいです。ありがとう! –
私たちはすべて初心者ですが、恥ずかしいことは何もありません。 – eolith