2

I'm exploring the possibilities of using the JPA metamodel with the Criteria API.

I have some entities that have attributes like this:

@Column( name = "defaultValue" )
@Convert( converter = StringListToStringConverter.class )
private List<String> defaultValue;

The DB column is a VARCHAR that holds a comma-separated list of strings (it's a legacy table). The converter nicely allows to use a real collection type when working with this entity attribute. But I'm confused by the metamodel that EclipseLink creates. The attribute is represented like this:

 public static volatile SingularAttribute<MyEntity, List> defaultValue;
  1. The raw type warning this declaration triggers is a little ugly. Is this enforced by the specification? Is there anything that would prevent the declaration to be this instead:

    public static volatile SingularAttribute<MyEntity, List<String>> defaultValue;
    
  2. I wonder if this declaration can lead to problems when I construct Criteria queries based on this metamodel. For example, would it be possible to construct a filter that checks if some specific value is contained in the list, something like

    [...] where( literal( "element" ).in( entity.get( defaultValue ) ) )
    

    (maybe this makes no sense at all - I've really just started with the Criteria API basics)

  3. Am I right to assume that a ListAttribute was not selected as the type for the metamodel here because the CollectionAttributes in general are only used for expressing relationships with other entities/element collections?

Hein Blöd
  • 1,553
  • 1
  • 18
  • 25
  • A List should become a ListAttribute, as per JPA 2.1 spec 6.2.1.1. If EclipseLink sets it as SingularAttribute then it is a bug which you should raise with them. Maybe Oracle's private JPA TCK doesn't test for basic stuff like that?! which clearly wouldn't happen if it was public and people could have a transparent way of viewing JPA compliance – Neil Stockton Oct 15 '15 at 12:35
  • @NeilStockton Thanks - I created a bug report [here](https://bugs.eclipse.org/bugs/show_bug.cgi?id=479912). – Hein Blöd Oct 16 '15 at 07:23

0 Answers0