我有这个查询:
SELECT * from (SELECT
*, (
6371 * acos (
cos ( radians(38.749817) )
* cos( radians( 39.116917 ) )
* cos( radians( -9.290633 ) - radians(-8.953753) )
+ sin ( radians(38.749817) )
* sin( radians( 39.116917 ) )
) ) AS distance
FROM amb.sync_collection_points ) as t
WHERE distance > 30
order by distance
limit 20
并且我想使用Criteria api解决此问题,但是我对此并不陌生,我真的不知道如何从这里开始。
这就是我到目前为止所得到的:
SessionFactory session = HibernateUtil.getSessionJavaConfigFactory();
CriteriaBuilder cb = session.getCriteriaBuilder();
CriteriaQuery<SyncCollectionPoints> cr = cb.createQuery(SyncCollectionPoints.class);
Root<SyncCollectionPoints> root = cr.from(SyncCollectionPoints.class);
Session sess = session.openSession();
List<Predicate> predicates = new ArrayList<Predicate>();
for (String residue : residues) {
predicates.add(cb.like(root.get("residuesToSearch"), "%" + "\"family_name\":\"" + residue.toLowerCase() + "%"));
}
cr.select(root).where(predicates.toArray(new Predicate[] {}));
List<SyncCollectionPoints> result= q.getResultList();
如您所见,我已经开始了查询,并且工作正常,但是我想将两者都附加到一个。