Orm.xml does not cancel annotations

I had a problem when JPA on Derby sets the BLOB size to 64K by default. I can solve this problem by setting columnDefinition = "BLOB (128M)" . However, this fails during testing integration with another DBMS, such as MS SQL. What I would like to do is set columnDefinition using orm.xml. However, my attempts were futile and I cannot get this to work. It doesn't seem that the values ​​set in orm.xml override the annotations as I expected.

I am using JPA 1.0, Toplink Essentials 2.1.60.

I have the following object annotated as such:

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 (located in 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> 

It is interesting to note that if I change the entity class or the base name attribute in orm.xml, it complains that it is invalid / not found. So this tells me that he is reading it, but does not cancel the annotation specified for the file . Even the default scheme is not used.

Doesn't that mean that orm.xml overrides annotations? Shouldn't it be easy?

+4
source share
1 answer

Figured out my problem. I did not understand that the project also has the same name of the unit of conservation defined in the persistence.xml file in the test / resources. Therefore when i added

 <mapping-file>META-INF/orm.xml</mapping-file> 

to persistence.xml, it worked. So yes, it seems that there is an error with toplink, as it should automatically choose, but it doesn’t. I can’t believe that I haven’t seen this before. Sigh...

+2
source

Source: https://habr.com/ru/post/1389557/


All Articles