2

Spring 3.1.1 Maven 3.0.4 JPA Eclipse wtp indigo

您好,我在服务器启动时收到以下异常。我的项目中只有一个 persistence.xml。有任何想法吗?谢谢埃里克

引起:java.lang.IllegalStateException:名称“cassandra_pu”的持久性单元定义冲突:文件:/C:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/cassandra/WEB -INF/classes/,文件:/C:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/cassandra/WEB-INF/classes/ at org.springframework.orm.jpa .persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:362) at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:326) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java :235) 在 org.springframework.orm.jpa.AbstractEntityManagerFactoryBean。afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) ... 62 更多

我的上下文文件:

<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
        xmlns:mvc="http://www.springframework.org/schema/mvc"  
        xmlns:context="http://www.springframework.org/schema/context"  
        xmlns:tx="http://www.springframework.org/schema/tx"  
        xmlns:p="http://www.springframework.org/schema/p"  
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
        xsi:schemaLocation="http://www.springframework.org/schema/beans  
        http://www.springframework.org/schema/beans/spring-beans-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/mvc  
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
        http://www.springframework.org/schema/tx   
        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">  

    <context:component-scan base-package="hamacher.cassandra.controller" />  
    <context:component-scan base-package="hamacher.cassandra.dao" />  
    <context:component-scan base-package="hamacher.cassandra.service" />  
    <context:annotation-config />  



    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="prefix" value="/WEB-INF/jsp/"/>  
        <property name="suffix" value=".jsp"/>  
    </bean>  

  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">    
    <property name="packagesToScan" value="hamacher.cassandra.entity"/>   
      <property name="persistenceUnitName" value="cassandra_pu"/>  
  </bean>    


    <tx:annotation-driven />  
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">  
        <property name="entityManagerFactory" ref="entityManagerFactory" />  
</bean>  


</beans>  

我的 persistence.xml 文件位于 META-INF 中它应该在的位置:

   <persistence 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"  
        version="2.0">  
        <persistence-unit name="cassandra_pu">  
            <provider>com.impetus.kundera.KunderaPersistence</provider>       
            <properties>            
                <property name="kundera.nodes" value="localhost"/>  
                <property name="kundera.port" value="9160"/>  
                <property name="kundera.keyspace" value="KunderaExamples"/>  
                <property name="kundera.dialect" value="cassandra"/>  
                <property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.pelops.PelopsClientFactory" />  
                <property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider"/>  
                <property name="kundera.cache.config.resource" value="/ehcache-test.xml"/>                  
            </properties>       
        </persistence-unit>  
    </persistence>  
4

1 回答 1

2

尝试添加,

<bean
    class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

<bean id="emf-p"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <!-- <property name="persistenceXmlLocation" value="/WEB-INF/classes/META-INF/persistence.xml" /> -->
            <property name="persistenceUnitManager" ref="pum"/>
        <property name="persistenceUnitName" value="personnel_cass_pu" />
    <property name="loadTimeWeaver">
        <bean
            class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
    </property>
</bean>

使用 Spring bean 定义您的 persistence.xml 位置。

也可以参考: https ://github.com/xamry/twitampl/blob/master/src/main/resources/appContext.xml

具体persistence.xml配置。

于 2012-07-27T10:49:52.047 回答