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;
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;
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)
Am I right to assume that a
ListAttribute
was not selected as the type for the metamodel here because theCollectionAttribute
s in general are only used for expressing relationships with other entities/element collections?