When I call the getName method of the SingularAttribute class I get a nullpointerexception. I've been stuck here for a couple of hours and for the life of me I can't figure out why this is breaking so I decided to ask ya'll for some thoughts on this issue. I assume somewhere my annotations are incorrect, or that I'm missing a step when creating my auto generated-source files.
This is an example of the call I'm making:
SingularAttribute attribute = criteria.getAttribute();
if( attribute == null )
System.out.println("Attribute is null");
else
System.out.println(attribute.getName());
Here is the exception, it occurs on the attribute.getName() call:
Exception in thread "main" java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.metamodel.proxy.AttributeProxyImpl.getName(AttributeProxyImpl.java:73)
at test.core.Test.main(Main.java:47)
I have auto generated-source files that contain metamodel data of my entities, Here is an example of my entity, and my metamodel:
@Entity
@Table(name = "cards")
public class Card {
@Column(unique = true)
private String name;
}
@Generated(value="EclipseLink-2.6.0.v20140809-rNA", date="2015-01-07T09:16:03")
@StaticMetamodel(Card.class)
public class Card_ {
public static volatile SingularAttribute<Card, String> name;
}
Here is my Criteria class:
public class Criteria<T,U extends Serializable> {
private final SingularAttribute<? super T, U> attribute;
private final U parameter;
private final CriteriaOperator operator;
Criteria(SingularAttribute<? super T, U> attribute, U parameter, CriteriaOperator operator) {
this.attribute = attribute;
this.parameter = parameter;
this.operator = operator;
}
public static enum CriteriaOperator{
AND,OR,NOT;
}
public SingularAttribute<? super T, U> getAttribute() {
return attribute;
}
public U getParameter() {
return parameter;
}
public CriteriaOperator getOperator() {
return operator;
}
}
Here is where I create a new instance of the criteria class
33 public static void main(String[] args) {
34
35 Criteria<Card, String> criteria = new Criteria<Card, String>(Card_.name, "test", CriteriaOperator.AND);
36
37 if (criteria == null) {
38 System.out.println("Criteria is null");
39 } else {
40 System.out.println(criteria.getOperator().name());
41
42 SingularAttribute<? super Card, String> attribute = criteria.getAttribute();
43 if( attribute == null )
45 System.out.println("Attribute is null");
46 else
47 System.out.println(attribute.getName());
48
49 System.out.println(criteria.getParameter().toString());
50 }
51
52 }
Edit 1: Removed the gui components to make the example more trivial, included the main function that instantiates the criteria class.