6

同様の質問がありますが、受け入れられた解決策は適用されませんでした (この同様の質問にあるように、Spring MVC によって何らかの形で発生した問題: Spring 3.1 + Hibernate 4.1 JPA, Entity manager factory is registered times )

明確にするために、私の唯一の問題は、エンティティ マネージャー ファクトリ (emf) の名前が 2 回登録されているという警告です。警告にもかかわらず、JPA の使用に問題はありません。

それで、春がそれをしていない場合、EMF名はどのように初めてロードされますか?

環境: Glassfish v 3.1.1、Spring 3.1.1、JPA 2.0 (Hibernate-entity-manager 4.1.0)、Struts2

次の警告が表示されます。

WARN: HHH000436: Entity manager factory name (empsys) is already registered.  If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'

これはサーバーログの一部です(最後の行は警告です。上部を切り落としましたが、残りは連続しています):

INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
INFO: HHH000412: Hibernate Core {4.1.0.Final}
INFO: HHH000206: hibernate.properties not found
INFO: HHH000021: Bytecode provider name : javassist
INFO: HHH000204: Processing PersistenceUnitInfo [
    name: empsys
    ...]
INFO: HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory
INFO: HHH000397: Using ASTQueryTranslatorFactory
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: PWC1412: WebModule[null] ServletContext.log():No Spring WebApplicationInitializer types detected on classpath
INFO: PWC1412: WebModule[null] ServletContext.log():Initializing Spring root WebApplicationContext
INFO: Root WebApplicationContext: initialization started
INFO: Refreshing Root WebApplicationContext: startup date [Sat Sep 01 19:14:15 MDT 2012]; root of context hierarchy
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
INFO: JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
INFO: JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO: Bean 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#3170938b' of type [class org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO: Bean 'dataSource' of type [class org.springframework.jndi.JndiObjectFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO: Bean 'dataSource' of type [class com.sun.gjc.spi.jdbc40.DataSource40] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO: Building JPA container EntityManagerFactory for persistence unit 'empsys'
INFO: HHH000204: Processing PersistenceUnitInfo [
    name: empsys
    ...]
INFO: HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory
INFO: HHH000397: Using ASTQueryTranslatorFactory
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
WARN: HHH000436: Entity manager factory name (empsys) is already registered.  If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>  
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>  
    <welcome-file-list>
        <welcome-file>/index.action</welcome-file>
    </welcome-file-list>
</web-app>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:jdbc="http://www.springframework.org/schema/jdbc"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/jdbc
            http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/jee 
            http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
    <context:annotation-config/>            
    <context:component-scan base-package="com.kenmcwilliams.employmentsystem" />
    <jee:jndi-lookup id="dataSource" jndi-name="jdbc/empsys" /> 
    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <!--  <property name="persistenceUnitName" value="empsys" /> -->
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
        </property>
        <property name="dataSource" ref="dataSource"/>

    </bean>
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
    <tx:annotation-driven  transaction-manager="transactionManager"/>
</beans>

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="empsys" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>jdbc/empsys</jta-data-source>
    <class>com.quaternion.orm.Something</class>
    <properties>
      <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/> 
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
    </properties>
  </persistence-unit>
</persistence>
4

2 に答える 2

4

HibernateはこのPUのEMFを2回作成するように求められているようです。Hibernateは、レジストリに構築された各EMFを追跡します。この警告は、EMFが同じPU名ですでに登録されていることを示しています。警告が続くと、そのEMFを使用してアプリケーションをクラスター化すると、問題になる可能性があることがわかります。それ以外の場合は、状況(およびその解決方法)について通知する単なる警告です。

于 2012-09-02T13:42:33.143 に答える
2

問題はここで解決できると思います:

<context:component-scan base-package="com.kenmcwilliams.employmentsystem" />

@Component でアノテーションが付けられた JPA のパッケージ/クラス、特にエンティティマネージャー Bean を作成するパッケージ/クラスを除外する必要があります。

@Component でアノテーションが付けられたクラスは、少なくともルート コンテキストの JPA 構成については、デフォルトでスキャンされます。

同じ問題があり、JPA 構成クラスをコンポーネント スキャンから除外することで解決しました。

于 2014-10-21T17:52:31.807 に答える