是的!
我找到了!
本人簡歷: 在我applicationContext.xml中,我輸入數據庫資源:
<!-- included Spring contexts -->
<import resource="classpath:META-INF/contacts/contexts/db_context.xml"/>
在db_context.xml,我宣佈一個JPA的entityManagerFactory(我指的是persistence.xml中):
<!-- Declare a JPA entityManagerFactory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:META-INF/contacts/hibernate/persistence.xml" />
<property name="persistenceUnitName" value="hibernatePersistenceUnit" />
<property name="jpaVendorAdapter" ref="hibernateVendor" />
</bean>
在persistence.xml中,我定義的映射文件(orm.xml中):
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="hibernatePersistenceUnit" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
.....
</properties>
<mapping-file>META-INF/contacts/hibernate/orm.xml</mapping-file>
</persistence-unit>
</persistence>
在這個orm.xml文件,我定義....什麼:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.0" xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">
<persistence-unit-metadata>
<persistence-unit-defaults>
</persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings>
但它的作品,如果沒有行家模塊(僅一個Maven項目(包括所有包和conf文件),或者如果休眠包存在於每個模塊中!
所以這是我的新orm.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.0" xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">
<package>com.mc.appcontacts.domain.hibernate</package>
<entity class="Client">
<table name="client" />
</entity>
<entity class="Contact">
<table name="contact" />
</entity>
<entity class="SystemUser">
<table name="system_user" />
</entity>
<entity class="User">
<table name="user" />
</entity>
<entity class="Userlogin">
<table name="userlogin" />
</entity>
<entity class="Userauth">
<table name="userauth" />
</entity>
<!-- <persistence-unit-metadata>
<persistence-unit-defaults>
</persistence-unit-defaults>
</persistence-unit-metadata> -->
</entity-mappings>
而且它只有在ContactCore模塊定義我的Hibernate包工程!
你可以在ascii樹中發佈項目結構嗎?http://stackoverflow.com/questions/1581559/ascii-library-for-creating-pretty-directory-trees以及你移動哪個文件導致問題 –
你不用不必這樣做。還有其他的錯誤。 –