【问题标题】:JpaRepository count query QuerySyntaxException entity is not mappedJpaRepository 计数查询 QuerySyntaxException 实体未映射
【发布时间】:2014-03-04 23:01:02
【问题描述】:
public interface EventoRepository extends JpaRepository<Evento, String>,     JpaSpecificationExecutor<Evento> {  
public Evento findById(String id);
public List<Evento> findByStatus(String status, Pageable page);
public List<Evento> findById_User(Long id_user,Pageable page);

@Query("select count(e) FROM evento e WHERE e.status = ?1 AND e.id_user = ?2")
int countByStatus(String status, long id_user);

@Query("SELECT count(e) FROM evento e WHERE e.id_user= ?1")
int countAll(long id_user);

@Query("SELECT count(e) FROM evento e WHERE e.status IS NOT = ?1 AND e.id_user = ?2")
int countBySospesi(String status, long id_user);
}

我有这种情况,当我在 apache Tomcat 中启动我的项目时,它会生成异常: - 原因:java.lang.IllegalArgumentException:查询方法 public abstract java.lang.Long net.petrikainulainen.spring.social.signinmvc.user.repository.EventoRepository.countAll(long) 的验证失败! - 原因:java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: eventto 未映射 [SELECT count(e) FROM eventto e WHERE e.id_user= ?1] - 原因:org.hibernate.hql.internal.ast.QuerySyntaxException:evento 未映射 [SELECT count(e) FROM eventto e WHERE e.id_user= ?1]

谁能帮我找出这个异常的原因吗?

【问题讨论】:

    标签: mysql sql spring hibernate jpa


    【解决方案1】:

    类名是Evento,而不是evento。所以你的查询应该是

    select count(e) from Evento e ...
    

    【讨论】:

      【解决方案2】:
      @Query("select count(e) FROM event e WHERE e.status = 1 AND e.id_user = 2")
      int countByStatus(String status, long id_user);
      

      【讨论】:

      • 考虑在代码中添加一个小解释。所以不鼓励代码只回答。
      • 虽然欢迎使用此代码 sn-p,并且可能会提供一些帮助,但它会是 greatly improved if it included an explanation of howwhy 这解决了问题。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人!请edit您的答案添加解释,并说明适用的限制和假设。
      猜你喜欢
      • 2019-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-22
      • 2020-01-15
      • 2014-09-18
      • 1970-01-01
      相关资源
      最近更新 更多