提问者:小点点

使用参数jsf更新HQL查询时出现IllegalArgumentException


我有问题要问你,我的更新查询(hql)有什么问题?它之前工作正常,但当我添加@参数时显示错误。这是我的语法有问题吗?下面的代码:

@Modifying
@Query("UPDATE InterimOrders io SET date12 = NULL,onceAMonthOpt12 = NULL, onceA2MonthOpt12 = NULL,yesNoOpt12 = NULL,totalCostOfExecusion12 = NULL,reportWithoutComments12 = NULL,reportWithoutCommentsForBusiness12 = NULL,information12 = NULL WHERE io.reportWithoutComments12 like '%Tak%' AND io.id = :id")     
Integer updateUserDate12(@Param("id")Integer id);

< br>
我有以下错误:< br>

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'interimOrdersRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: java.lang.NullPointerException
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1442)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:305)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:876)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
... 38 more
Caused by: java.lang.IllegalArgumentException: java.lang.NullPointerException
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.<init>(SimpleJpaQuery.java:73)
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.fromQueryAnnotation(SimpleJpaQuery.java:132)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:114)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:160)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:68)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:280)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:148)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:125)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:41)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
... 46 more
Caused by: java.lang.NullPointerException
at org.hibernate.hql.internal.ast.ParameterTranslationsImpl.getNamedParameterExpectedType(ParameterTranslationsImpl.java:87)
at org.hibernate.engine.query.spi.HQLQueryPlan.buildParameterMetadata(HQLQueryPlan.java:319)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:124)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1735)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:291)
at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
at com.sun.proxy.$Proxy40.createQuery(Unknown Source)
at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
at com.sun.proxy.$Proxy40.createQuery(Unknown Source)
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.<init>(SimpleJpaQuery.java:69)
... 55 more



我的存储库:

@Transactional
public interface InterimOrdersRepository extends CrudRepository<InterimOrders, Integer>{
@Modifying
@Query("UPDATE InterimOrders io SET date12 = NULL,onceAMonthOpt12 = NULL, yesNoOpt12 = NULL,totalCostOfExecusion12 = NULL,reportWithoutComments12 = NULL,reportWithoutCommentsForBusiness12 = NULL,information12 = NULL WHERE io.date12 < DATE_FORMAT(CURRENT_DATE, '%Y-%m-%e') AND io.id = :id")       
Integer updateDate12(@Param("id")Integer id);<br />
@Modifying
@Query("INSERT INTO InterimOrdersData  (activityName,interimOrdersId,dateOfExecution,status,status1,status2,onceAMonthOpt12,onceA2MonthOpt12,yesNoOpt12,totalCostOfExecusion12,reportWithoutComments12,reportWithoutCommentsForBusiness12,information12,activityTitle, date12) SELECT activityName,id,dateOfExecution,status,status1,status2,onceAMonthOpt12,onceA2MonthOpt12,yesNoOpt12,totalCostOfExecusion12,reportWithoutComments12,reportWithoutCommentsForBusiness12,information12,activityTitle, date12 FROM InterimOrders io where io.reportWithoutComments12 like '%Tak%') AND io.id = :id")       
Integer copyUserDate12(@Param("id")Integer id);

List<InterimOrders> findAll();



我的Bean:

@ManagedBean@ViewScoped公共类InterimOrdersBean实现可序列化{

private static final long serialVersionUID = 8513710412378099452L;

public InterimOrdersRepository getInterimOrdersRepo(){
    return (InterimOrdersRepository) RepositoryHelper.getRepo("interimOrdersRepository", InterimOrdersRepository.class);


}
 public void UpdateDate12(Integer id) throws IOException{ 
     System.out.println("Update Date 12");
     System.out.println("id = "+id);
     getInterimOrdersRepo().copyUserDate12(id);
     System.out.println("copyUserDate12");

     getInterimOrdRepo().updateUserDate12(id);
     System.out.println("updateUserDate12");
        return;

}你还需要什么吗?谢谢


共2个答案

匿名用户

HQL/JPQL 查询中缺少或多余的括号会导致这种类型的错误。

匿名用户

似乎java类型的ID不正确。

通常是长型或字符串型。

尝试将方法声明更改为

Integer updateUserDate12(@Param("id")Long id);