Datanucleus RDBMS JPA Entitymanager GAE Criteriabuilder多次联接错误org.datanucleus.store.rdbms.query.QueryToSQLMapper

时间:2018-09-26 12:29:53

标签: java mysql google-app-engine jpa datanucleus

我遇到此错误

  

java.lang.NullPointerException在   org.datanucleus.store.rdbms.query.QueryToSQLMapper.compileFromClassExpression(QueryToSQLMapper.java:1199)     在   org.datanucleus.store.rdbms.query.QueryToSQLMapper.compileFrom(QueryToSQLMapper.java:436)     在   org.datanucleus.store.rdbms.query.QueryToSQLMapper.compile(QueryToSQLMapper.java:380)     在   org.datanucleus.store.rdbms.query.JPQLQuery.compileQueryFull(JPQLQuery.java:799)     在   org.datanucleus.store.rdbms.query.JPQLQuery.compileInternal(JPQLQuery.java:280)     在org.datanucleus.store.query.Query.executeQuery(Query.java:1747)     在org.datanucleus.store.query.Query.executeWithMap(Query.java:1693)     在org.datanucleus.api.jpa.JPAQuery.getResultList(JPAQuery.java:185)     在...........

我尝试执行

      EntityManager mgr = null;
      Cursor cursor = null;
      List<StudentMark> execute = null;

    try {

        mgr = getEntityManager();
        CriteriaBuilder cb = mgr.getCriteriaBuilder();
        CriteriaQuery<StudentMark> query = cb
                .createQuery(StudentMark.class);
        Root<StudentMark> from = query.from(StudentMark.class);
        CriteriaQuery<StudentMark> select = query.select(from);

        List<Predicate> predicates = new ArrayList<Predicate>();

        /* Set of Filters Use to Filter Query Results */
        if (subjectId != null) {
            predicates.add(cb.equal(from.join("subject").get("subjectId"),
                    cb.parameter(Long.class, "subjectId")));
        }

        if (studentRecordId != null) {
            predicates.add(cb.equal(from.join("studentRecord").get("studentRecordId"),
                    cb.parameter(Long.class, "studentRecordId")));

        }


        query.select(from).where(predicates.toArray(new Predicate[] {}));

        TypedQuery<StudentMark> typedQuery = mgr.createQuery(select);

        /* set the parameters of the above mentioned filters */
        if (subjectId != null) {
            typedQuery.setParameter("subjectId", subjectId);
        }
        if (studentRecordId != null) {
            typedQuery.setParameter("studentRecordId", studentRecordId);
        }

        if (limit != null) {
            typedQuery.setFirstResult(0);
            typedQuery.setMaxResults(limit);
        }

        execute = (List<StudentMark>) typedQuery.getResultList();
    } finally {
        mgr.close();
    }

当我尝试同时传递2个参数进行查询时创建错误。如果我仅传递一个参数,则结果生成会很好。

我正在使用这些罐子Jars 并将Google App Engine标准项目与Cloud sql一起使用 这是我的persistance.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">


 <persistence-unit name="Demo">
  <properties>
      <property name="javax.persistence.jdbc.user" value="root" />
      <!-- this is required if you're connecting to a 2nd generation cloud-sql db -->
      <property name="javax.persistence.jdbc.password" value="zaq123!@#" />
      <property name="datanucleus.autoCreateSchema" value="true"/>
  </properties>
 </persistence-unit>

0 个答案:

没有答案