我有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.怎么了?
我有一个 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 ×2
biginteger ×1
collections ×1
hibernate ×1
jpa ×1
long-integer ×1
spring-boot ×1
sql ×1
sql-server ×1