Java 名称的持久化单元定义冲突

Java 名称的持久化单元定义冲突,java,spring,hibernate,persistence,entitymanager,Java,Spring,Hibernate,Persistence,Entitymanager,运行我的jar时出现此异常 java.lang.IllegalStateException: Conflicting persistence unit definitions for name 'hibernateUnit': file:/D:/Assignment.jar, file:/D:/Assignment.jar My persistence.xml <persistence version="1.0" xmlns="http://java.sun.

运行我的jar时出现此异常

java.lang.IllegalStateException: Conflicting persistence unit definitions 
for name 'hibernateUnit': file:/D:/Assignment.jar, file:/D:/Assignment.jar
My persistence.xml

<persistence version="1.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_1_0.xsd">
    <persistence-unit name="hibernateUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>EventImpl</class>           
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format.sql" value="true"/>
            <property name="hibernate.connection.driver_class" value="${db.driver.name}"/>
            <property name="hibernate.connection.url" value="${db.url.value}"/>
            <property name="hibernate.connection.username" value="${db.user.name}"/>
            <property name="hibernate.connection.password" value="${db.user.password}"/>
        </properties>
    </persistence-unit>
</persistence>

org.hibernate.ejb.HibernatePersistence
EventImpl
My applicationContext.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:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
    <context:annotation-config/>
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <context:property-placeholder location="db.properties"/>       
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${db.driver.name}"/>
        <property name="url" value="${db.url.value}"/>
        <property name="username" value="${db.user.name}"/>
        <property name="password" value="${db.user.password}"/>
    </bean>       
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="persistenceUnitName" value="hibernateUnit"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
        </property>
        <property name="loadTimeWeaver">
            <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
        </property>
    </bean>
    <bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>      
</beans>


有趣的是,当我在Idea中运行它时,效果非常好。这仅在尝试运行此应用程序的jar文件时发生。

尝试在
entityManagerFactory
bean中指定持久性XML文件的确切位置:


运行jar的命令是什么?您找到解决此问题的方法了吗??