我遇到了Derby上的JPA將BLOB大小默認爲64KB的問題。我可以通過設置columnDefinition =「BLOB(128M)」來解決此問題。但是,在針對MS SQL等其他RDBMS進行集成測試期間,此操作失敗。我想要做的是使用orm.xml設置columnDefinition。然而,我的嘗試是徒勞的,我無法得到這個工作。它看起來不像orm.xml中設置的值正如我所期望的那樣覆蓋註釋。orm.xml不會覆蓋註釋
我正在使用JPA 1.0,Toplink Essentials 2.1.60。
我有以下實體這樣的註釋:
package foo;
@Entity
@Table(name = "Attachment")
public class Attachment implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Version
@Column(name = "VERSION")
private Integer version;
@Column(name = "FILE_NAME", nullable = false)
private String name;
@Lob
@Basic
@Column(name = "ATTACHED_FILE", nullable = false)
private byte[] file;
}
的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<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="LAS-OOC" transaction-type="RESOURCE_LOCAL">
<provider>${jpa.provider}</provider>
<!-- this isn't required, i know, but I'm trying everything I can think of -->
<mapping-file>META-INF/orm.xml</mapping-file>
<class>foo.Attachment</class>
<properties>
...
</properties>
</persistence-unit>
</persistence>
orm.xml中(位於META-INF)
<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings 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_1_0.xsd" version="1.0">
<persistence-unit-metadata>
<persistence-unit-defaults>
<schema>TEST</schema>
</persistence-unit-defaults>
</persistence-unit-metadata>
<entity class="foo.Attachment" access="FIELD" >
<attributes>
<basic name="file">
<!--
I'm using maven profiles to set the 'jpa.blob.definition' property. I even tried changing the column name.
-->
<column nullable="true" name="ATTACHED_FILE_MODIFIED" column-definition="${jpa.blob.definition}" />
</basic>
</attributes>
</entity>
</entity-mappings>
有趣的是,要注意的是,如果我更改orm.xml中的實體類或基本名稱屬性,它會抱怨它無效/未找到。所以這告訴我它正在閱讀它,但它並不覆蓋文件指定的註釋。即使默認架構沒有被使用。
是不是orm.xml重寫註釋?這不應該簡單嗎?
很確定你可以覆蓋像使用DataNucleus JPA這樣的信息,因爲我們積極鼓勵人們這樣做。也許它是TopLink中的一個錯誤? – DataNucleus 2012-01-06 14:58:10