0

I'm using Eclipse 4.5.0 for an EclipseLink 2.5 project. Eclipse is generating the metamodel for my entities, which works fine except for this case:

Entity:

public class User implements Serializable {
    private String id;
    private Set<String> groupNames;
}

Mapping:

<attributes>
    <id name="id" />
    <element-collection name="groupNames" fetch="EAGER" target-class="java.lang.String">
        <column name="USERGROUP_NAME"/>
        <collection-table name="USER_GROUP_MEMBERSHIP">
            <join-column name="MEMBERS_ID" referenced-column-name="ID"/>
        </collection-table>
    </element-collection>
</attributes>

The generated model looks like this:

public class User_ {
    public static volatile SingularAttribute<User, String> id;
    public static volatile SetAttribute<User, Object> groupNames;
}

Even though I explicitly defined the target class to be a String, the model suggests groupNames to be Set<Object> rather than Set<String> Did I miss anything? Is there any way to force the metamodel generation to use String instead of Object?

Alex Salauyou
  • 14,185
  • 5
  • 45
  • 67
Nitek
  • 2,515
  • 2
  • 23
  • 39
  • I have a class similar to that and DataNucleus JPA metamodel generator generates the value type as String (when using annotations). One thing to note though ... this is precompile and so only the class is necessarily available (XML files are not necessarily in the CLASSPATH at compile, or guaranteed to be read), hence put it as an annotation and it may work for you – Neil Stockton Aug 27 '15 at 13:43
  • Unfortunately annotations are not an option in our case because we need to keep the dependencies out, but of course there is still the workaround to change the metamodel manually. – Nitek Aug 27 '15 at 13:51
  • Well annotations are kinda necessary to a level since this generation is done using an "annotation processor", and the key is in the name. http://docs.oracle.com/javase/8/docs/api/javax/annotation/processing/AbstractProcessor.html – Neil Stockton Aug 27 '15 at 13:56
  • 1
    @NeilStockton The nice thing about the metamodel generated by Eclipse is that it is triggered by changes in both the Java annotations and the XML files.That said, this looks like a bug in Dali (the Eclipse JPA tooling plug-in). From what I can see Dali will generate the correct code if the element type is an embeddable, but it does not handle basic types correctly. – Brian Vosburgh Aug 28 '15 at 01:42
  • I created a bug report for this issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=476185 - Looks like I have to fix the model by hand until it is fixed. – Nitek Sep 02 '15 at 14:26

0 Answers0