相关疑难解决方法(0)

java.math.BigInteger无法强制转换为java.lang.Long

我有List<Long> dynamics.我希望得到最大的结果Collections.这是我的代码:

List<Long> dynamics=spyPathService.getDynamics();
        Long max=((Long)Collections.max(dynamics)).longValue(); 
Run Code Online (Sandbox Code Playgroud)

这是我的getDynamics:

public List<Long> getDynamics() {

        Session session = null;

        session = this.sessionFactory.getCurrentSession();
        Query query = session
                .createSQLQuery("SELECT COUNT(*) FROM SpyPath WHERE DATE(time)>=DATE_SUB(CURDATE(),INTERVAL 6 DAY) GROUP BY DATE(time) ORDER BY time;");

        List<Long> result = query.list();
        return result;

    }
Run Code Online (Sandbox Code Playgroud)

现在我来了java.math.BigInteger cannot be cast to java.lang.Long.怎么了?

java collections hibernate biginteger long-integer

22
推荐指数
3
解决办法
10万
查看次数

Spring JPA 中的 SQL 聚合 GROUP BY 和 COUNT

我有一个 SQL 表:

@Table(name = "population_table")
public class Population {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  private String country;
  private String state;
  private String area;
  private String population;
}
Run Code Online (Sandbox Code Playgroud)

我想获得一个计数,按国家和州分组,输出类为计数列表:

  private static class Count {
    private String country;
    private String state;
    private long count;
  }
Run Code Online (Sandbox Code Playgroud)

我知道查询是

SELECT country, state, Count(*)
FROM population_table
GROUP BY country, state
Run Code Online (Sandbox Code Playgroud)

但我想使用 JPA 规范来做到这一点。如何在 Spring Boot 中使用 JPA 规范来实现这一目标?

java sql sql-server jpa spring-boot

3
推荐指数
1
解决办法
1万
查看次数