我遇到了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