I have a JPA entity class which is configured entirely from orm.xml (no annotations). One of the properties of the entity class is a String[] which is converted to a plain String representation on the database side via a javax.persistence.AttributeConverter<String[], String> implementation. I'd like to generate the metamodel information for the entity using org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor or similar.
However, JPAMetaModelEntityProcessor seems to ignore the conversion defined in orm.xml as it throws the following error:
--- maven-processor-plugin:2.2.4:process (process) @ ConverterTest ---
diagnostic: warning: Unable to determine type for property tags of class test.convertertest.Post using access type FIELD
The configuration works fine if I use annotations instead of orm.xml, so I'm assuming the processor isn't able to determine the conversion types from the class generics. However, I'm not able to find any other way of explicitly defining these.
Note that the processor also runs fine (with expected outputs) if the array attribute is omitted.
I've tried replacing String[] with List<String> in the entity and converter, in which case the processor completes without issue but generates uncompilable code:
// Post_.java
public static volatile SingularAttribute<Post, List<E>> tags; // cannot find symbol E
Is this an undocumented bug/limitation, or am I missing a specification somewhere?
Below is an example entity class which illustrates the problem (contrived, mostly copied from here):
public class Post implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
// other stuff
private String[] tags;
// boilerplate nonsense
}
And here is the orm.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm http://xmlns.jcp.org/xml/ns/persistence/orm_2_2.xsd" version="2.2">
<persistence-unit-metadata>
<xml-mapping-metadata-complete/>
</persistence-unit-metadata>
<access>FIELD</access>
<entity class="test.convertertest.Post" name="Post">
<table name="POST"/>
<attributes>
<id name="id">
<column name="ID"/>
<generated-value strategy="AUTO"/>
</id>
<!-- other stuff -->
<basic name="tags">
<column name="TAGS"/>
<convert converter="test.convertertest.ListToStringConverter"/>
</basic>
</attributes>
</entity>
</entity-mappings>
Converter:
@Converter
public class ListToStringConverter implements AttributeConverter<String[], String> {
@Override
public String convertToDatabaseColumn(String[] attribute) {
return (attribute == null || attribute.length == 0) ? "" : String.join(",", attribute);
}
@Override
public String[] convertToEntityAttribute(String dbData) {
return (dbData == null || dbData.isEmpty()) ? new String[0] : dbData.split(",");
}
}
Relevant pom.xml entry:
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.2.4</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.1.Final</version>
</dependency>
</dependencies>
</plugin>
Thanks in advance!