JpaRepository计数查询QuerySyntaxException实体未映射

时间:2014-02-07 13:44:05

标签: mysql sql spring hibernate jpa

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:evento未映射[SELECT count(e)FROM evento e WHERE e.id_user =?1] - 引起:org.hibernate.hql.internal.ast.QuerySyntaxException:evento未映射[SELECT count(e)FROM evento e WHERE e.id_user =?1]

有人可以帮我找到这个例外的原因吗?

2 个答案:

答案 0 :(得分:1)

班级名称为Evento,而不是evento。所以你的查询应该是

select count(e) from Evento e ...

答案 1 :(得分:0)

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