我是Hibernate的新手。我的表和类之间的映射就是这样的。
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.pathfinder.beans.Location" table="VEHICLE_LOCATIONS">
<id name="rowId" column="position_id">
<generator class="native"></generator>
</id>
<property name="vehicleId" column="VEHICLE_ID"></property>
<property name="latitude" column="LATITUDE"></property>
<property name="longitude" column="LONGITUDE"></property>
<property name="time" column="TIME"></property>
<property name="createdtime" column="CREATEDTIME"></property>
</class>
</hibernate-mapping>
现在我需要为每辆车获得最新创建时间的纬度,经度和时间。使用SQL查询,我可以像
一样SELECT a.vehicle_id, a.latitude, a.longitude, a.time
FROM vehicle_locations a
LEFT JOIN vehicle_locations b ON a.vehicle_id = b.vehicle_id AND a.createdtime < b.createdtime
WHERE b.position_id IS NULL;
但是当我在HQL中尝试相同的连接时,它会出现类似
的错误java.lang.IllegalStateException:没有左侧的DOT节点!
如何使用hibernate获得预期的结果?
答案 0 :(得分:1)
您可以尝试使用以下HQL
select a.vehicle_id, a.latitude, a.longitude, a.time
FROM vehicle_locations a
LEFT JOIN vehicle_locations b with a.vehicle_id = b.vehicle_id AND a.createdtime < b.createdtime
WHERE b.position_id IS NULL;