Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 基于曼哈顿距离选择具有复合(嵌入)特性的对象_Java_Hibernate_Hql - Fatal编程技术网

Java 基于曼哈顿距离选择具有复合(嵌入)特性的对象

Java 基于曼哈顿距离选择具有复合(嵌入)特性的对象,java,hibernate,hql,Java,Hibernate,Hql,考虑以下对象类: +---------------------------+ +----------------------+ |Planet() | |Coordinate() | +---------------------------+ +----------------------+ |coordinates Coordinate() | |xcoordinate

考虑以下对象类:

+---------------------------+        +----------------------+
|Planet()                   |        |Coordinate()          |
+---------------------------+        +----------------------+
|coordinates   Coordinate() |        |xcoordinate       int |
|lastVisit              int |        |ycoordinate       int |
+---------------------------+        +----------------------+
我想得到那些离另一颗行星在z单位距离内的行星,但是只有那些最近访问次数最高的行星,所以我只得到最近的行星信息。同一颗行星可能在不同的最近访问中被多次保存

坐标对象用@Embeddeble注释,并且@embedded在行星对象中

在我的DAO中,我有这个方法,它几乎满足了我的需求——我只能提取这个星球的最新实例:

@Override
public List<Planet> getRecentPlanets() {
    Session session = sessionfactory.getCurrentSession();

    // create a query and sort it by last name using sql
    Query<Planet> theQuery = session.createQuery("FROM Planet p WHERE (p.coordinates.xcoordinate, p.coordinates.ycoordinate, p.lastVisit) in"
            + "(SELECT p1.coordinates.xcoordinate, p1.coordinates.ycoordinate, max(p1.lastVisit) FROM Planet p1 group by p1.coordinates)",
                                                            Planet.class);

    return theQuery.getResultList();
}
然而,我似乎无法理解如何在数据库端包含曼哈顿距离

我的问题是:

如何使用HQL在数据库端实现此选择? 这在性能方面有意义吗?是否适合在java类中进行距离计算? 如果我尝试使用hibernate标准,但我还不完全了解这些标准,那么在性能和详细性方面,我将如何获得相同的效果? 如果有一个更大的网格和更多的每轮访问量,答案会有所不同吗? 附加信息:数据库大小由大约500x500的稀疏曼哈顿网格限定。我估计不超过200次,每次大约50次