我遇到了同樣的問題,MS SQL Server希望定義目錄和模式,但HSQLDB沒有。我的解決方案是加載一個自定義的orm.xml文件(通過persistence.xml),專門用於設置目錄和模式的MS SQL Server。在META-INF/persistence.xml文件
@Entity
@Table(name="CATEGORY")
public static class Category { ... }
2.Specify兩種持久性單元節點:
1.Only對你的實體指定@Table名(忽略任何目錄或模式信息)
<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">
<!--
| For production and integration testing we use MS SQL Server, which needs
| the catalog and schema set (see orm-mssql.xml).
|-->
<persistence-unit name="com.mycompany.prod">
<mapping-file>META-INF/orm-mssql.xml</mapping-file>
</persistence-unit>
<!--
| For unit testing we use HSQLDB, which does not need the catalog or schema.
|-->
<persistence-unit name="com.mycompany.test" />
</persistence>
3.Specify默認的目錄和架構在ORM-mssql.xml文件:
<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 orm_2_0.xsd">
<persistence-unit-metadata>
<!--
| Set the catalog and schema for MS SQL Server
|-->
<persistence-unit-defaults>
<schema>MYSCHEMA</schema>
<catalog>MYCATALOG</catalog>
</persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings>
和你爸用SPRI NG配置JPA,所以我用一個屬性 - 佔位符persistenceUnitName來的價值:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="persistenceUnitName" value="${entityManagerFactory.persistenceUnitName}" />
</bean>
單元測試,使用「com.mycompany.test」和集成的測試/生產部署,使用「COM .mycompany.prod」。
已經有蟲子開放內容:HTTP://開源。 atlassian.com/projects/hibernate/browse/HHH-1853但顯然,開發人員不喜歡這個補丁(它現在已經開放*三年了)。這告訴我:永遠不會有修復。他們根本不在乎。所以我需要一個解決方法。 – 2009-06-04 10:49:35