我正尝试从我的应用程序中的JPARepository中获取聚合数据。在SQL比喻会是这样的:在JPARepository中获取聚合查询结果
SELECT c.sex as Sex, count(c.sex) as Count
FROM customer c
GROUP BY c.sex
的实体是:
@Entity(name = "customer")
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private Person.Sex sex;
...
}
和我JPARepository是:
public interface CustomerRepository extends JpaRepository<Customer, Long> {
@Query(value = "SELECT c.sex as Sex, count(c.sex) as Count FROM customer c")
List<Object[]> countBySex();
}
的SQL方法不返回任何结果,为什么它不,并且有没有非SQL方法?
我正在使用Spring 1.4.0.RELEASE。
提前致谢!
编辑:当我添加JPA的persistence.xml配置与有问题的类(Customer.class)的映射时SQL方法工作。