openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dominik Jall (JIRA)" <j...@apache.org>
Subject [jira] [Created] (OPENJPA-2501) MapJoin key() throws NullPointerException
Date Sat, 10 May 2014 22:16:20 GMT
Dominik Jall created OPENJPA-2501:
-------------------------------------

             Summary: MapJoin key() throws NullPointerException
                 Key: OPENJPA-2501
                 URL: https://issues.apache.org/jira/browse/OPENJPA-2501
             Project: OpenJPA
          Issue Type: Bug
          Components: criteria, kernel
    Affects Versions: 2.2.3
         Environment: openjpa-2.2.3-SNAPSHOT-r422266
used in IBM Websphere Liberty profile build 8.5.5.1-cl50120131011-1639
openjdk-1.7.0.45.x86_64
Eclipse Kepler Java EE Release 1 build 20130919-0819
            Reporter: Dominik Jall


I am trying to do a search on a localized string. The strings are mapped by an ElementCollection
of type Map. Key is a string interpreted as locale.

Here is the entity:

@Entity
@Table(name="category", schema="myschema")
@Access(AccessType.FIELD)
public class Category {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    Long id;

    @ElementCollection(fetch=FetchType.EAGER)
    Map<String, String> test = new HashMap<String, String>();

...
}

Here is the query:
String search = "%test%";
Locale locale = Locale.ENGLISH;
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Category> criteria = cb.createQuery(Category.class);
Root<Category> category = criteria.from(Category.class);
criteria.select(category);
MapJoin<Category, String, String> tests = category.join(Category_.test);

Predicate searchClause = cb.and(
                                cb.equal(tests.key(), locale.toString()), 
                                cb.like(tests.value(), search)
                               );

criteria.where(searchClause);
entityManager.createQuery(criteria).getResultList();

When the query is executed, I get this stack trace:

[err] java.lang.NullPointerException
[err]   at org.apache.openjpa.jdbc.kernel.exps.PCPath.<init>(PCPath.java:105)
[err]   at org.apache.openjpa.jdbc.kernel.exps.JDBCExpressionFactory.newPath(JDBCExpressionFactory.java:302)
[err]   at org.apache.openjpa.persistence.criteria.Joins$MapKey.toValue(Joins.java:625)
[err]   at org.apache.openjpa.persistence.criteria.Expressions.toValue(Expressions.java:66)
[err]   at org.apache.openjpa.persistence.criteria.Expressions$Equal.toKernelExpression(Expressions.java:851)
[err]   at org.apache.openjpa.persistence.criteria.PredicateImpl.toKernelExpression(PredicateImpl.java:171)
[err]   at org.apache.openjpa.persistence.criteria.CriteriaExpressionBuilder.evalFilter(CriteriaExpressionBuilder.java:216)
[err]   at org.apache.openjpa.persistence.criteria.CriteriaExpressionBuilder.getQueryExpressions(CriteriaExpressionBuilder.java:75)
[err]   at org.apache.openjpa.persistence.criteria.CriteriaQueryImpl.getQueryExpressions(CriteriaQueryImpl.java:418)
[err]   at org.apache.openjpa.persistence.criteria.CriteriaBuilderImpl.eval(CriteriaBuilderImpl.java:83)
[err]   at org.apache.openjpa.kernel.ExpressionStoreQuery$DataStoreExecutor.<init>(ExpressionStoreQuery.java:763)
[err]   at org.apache.openjpa.kernel.ExpressionStoreQuery.newDataStoreExecutor(ExpressionStoreQuery.java:179)
[err]   at org.apache.openjpa.kernel.QueryImpl.createExecutor(QueryImpl.java:749)

I assume the key() function returns an invalid or non-existing path.
When I remove the key() part the query works.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message