Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2501

MapJoin key() throws NullPointerException

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2.3
    • Fix Version/s: None
    • Component/s: criteria, kernel
    • Labels:
      None
    • 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

      Description

      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.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              domdom82 Dominik Jall
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: