JPA + SPRING = DAO。动态参数列表

时间:2011-08-21 12:17:12

标签: java hibernate jpa dao

我无法使用动态参数列表“where in”解决错误。另一个查询工作

@NamedQuery(name =“News.delete”,query =“DELETE n FROM News n WHERE n.newsId in(:ids)”)

但是

  

引起:java.lang.NoSuchMethodError:org.hibernate.hql.antlr.HqlBaseParser.recover(Lantlr / RecognitionException; Lantlr / collections / impl / BitSet;)V           在org.hibernate.hql.antlr.HqlBaseParser.optionalFromTokenFromClause(HqlBaseParser.java:400)           在org.hibernate.hql.antlr.HqlBaseParser.deleteStatement(HqlBaseParser.java:259)           在org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:148)           在org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:248)           在org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)           在org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)           在org.hibernate.engine.query.HQLQueryPlan。(HQLQueryPlan.java:77)           在org.hibernate.engine.query.HQLQueryPlan。(HQLQueryPlan.java:56)           在org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)           在org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:402)           在org.hibernate.impl.SessionFactoryImpl。(SessionFactoryImpl.java:352)           在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)           在org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)           在org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)           在org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:132)           在org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:221)           在org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:251)           在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1390)           在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1359)

UPD 新错误

 public void removeNews(List<Integer> listOfIdNewsForDeleting) throws DAOException {
    EntityManager entityManager = getJpaTemplate().getEntityManagerFactory().createEntityManager();

    Query query = entityManager.createNamedQuery("News.delete");
    query.setParameter("ids", listOfIdNewsForDeleting);
    int deleted = query.executeUpdate();}
  

javax.persistence.TransactionRequiredException:执行更新/删除查询

我无法获得交易。所以我不能使用JpaTemplate新闻ID的传递列表进行删除。也许JpaCallback

2 个答案:

答案 0 :(得分:1)

你有不兼容的hibernate和antlr版本。升级你的antlr.jar

答案 1 :(得分:0)

使用DELETE FROM News n WHERE n.newsId in (:ids)

请参阅http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#batch-direct以获取参考。