@Query不能在jpa中使用多个对象,错误 - 对于方法public abstract java.util.List

时间:2016-09-13 10:27:24

标签: java-ee spring-boot spring-data-jpa crud

当我在select查询中传递多个对象时,@ Query返回错误。

错误 - 查询方法public abstract java.util.List

时验证失败

POJO的

 @Entity
@Table(name = "SUBJECT")
public class Subject {

    private long id;
    private Long fkCode;
    private Long fkData;
    private Date assignedDate;
    private Data data;
    private Code code;

    //setters getters  


    @OneToOne
    @JoinColumn(name="fkCode",insertable=false, updatable=false)
    public Code getCode() {
        return code;
    }

    @OneToOne
    @JoinColumn(name="fkData",insertable=false, updatable=false)
    public Data getData() {
        return data;
    }
    public Subject(long id, Long fkEquipment, Long fkCode,Date assignedDate, Long fkData,Data data,Code code) {
        super();
        this.id = id;
        this.fkCode = fkCode;
        this.fkData = fkData;
        this.assignedDate = assignedDate;
        this.data = data;
        this.code=code;
        }

在我的资料库中

@Query(" select new Subject(id, fkCode, fkData, assignedDate, data, code)"
                + " from Subject a where trunc(a.assignedDate) = TO_DATE(?1, 'yyyy-mm-dd')  "
                + " order by a.id desc")
        List<Subject> findByAssignedDate(String assignedDate);

这是错误

  

引起:java.lang.IllegalArgumentException:验证失败   查询方法public abstract java.util.List   com.dei.repositories.SubjectRepository.findByAssignedDate(java.lang.String中)!     在   org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:92)     在   org.springframework.data.jpa.repository.query.SimpleJpaQuery。(SimpleJpaQuery.java:62)     在   org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:72)     在   org.springframework.data.jpa.repository.query.JpaQueryFactory.fromQueryAnnotation(JpaQueryFactory.java:53)     在   org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy $ DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:141)     在   org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy $ CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:209)     在   org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy $ AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:74)     在   org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor。(RepositoryFactorySupport.java:416)     在   org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:206)     在   org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251)     在   org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237)     在   org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)     ...省略了66个常见帧引起的:   java.lang.NullPointerException:null at   org.hibernate.internal.util.ReflectHelper.getConstructor(ReflectHelper.java:354)     在   org.hibernate.hql.internal.ast.tree.ConstructorNode.resolveConstructor(ConstructorNode.java:186)     在   org.hibernate.hql.internal.ast.tree.ConstructorNode.prepare(ConstructorNode.java:159)     在   org.hibernate.hql.internal.ast.HqlSqlWalker.processConstructor(HqlSqlWalker.java:1109)     在   org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2328)     在   org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:2194)     在   org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1476)     在   org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:573)     在   org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301)     在   org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:249)     在   org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:278)     在   org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:206)     在   org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)     在   org.hibernate.engine.query.spi.HQLQueryPlan。(HQLQueryPlan.java:131)     在   org.hibernate.engine.query.spi.HQLQueryPlan。(HQLQueryPlan.java:93)     在   org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167)     在   org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)     在   org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)     在   org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1836)     在   org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:328)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:601)at   org.springframework.orm.jpa.ExtendedEntityManagerCreator $ ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:344)     在com.sun.proxy。$ Proxy75.createQuery(未知来源)at   org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:86)     ...省略了79个常见帧

如果我从查询中删除代码或数据,它就可以工作..

@Query(&#34;选择新主题(id,fkCode,fkData,assignedDate,数据)&#34; - 正常工作

@Query(&#34;选择新主题(id,fkCode,fkData,assignedDate,代码)&#34; - 正常工作

@Query(&#34;选择新主题(id,fkCode,fkData,assignedDate,数据,代码)&#34; 无法正常工作

不合作。需要帮助/建议

0 个答案:

没有答案