我正在尝试搜索本地化字符串。 字符串由Map映射
这是实体:
@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>();
...
}
以下是查询:
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)
);
entityManager.createQuery(criteria).getResultList();
执行查询时,我得到了这个堆栈跟踪:
[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)
我不知道出了什么问题。显然key()函数无法正常工作。
我使用的是openjpa-2.2.3-SNAPSHOT-r422266