我有三个表设备,车辆和vehicle_device所有表都在一个模式'tcm'中,我试图通过'device imei'获得'车辆'。在Vehicle.class中,我有“Set devices”字段并创建maping:
Vehicle.hbm.xml
<hibernate-mapping package="hibernate.entity">
<class name="Vehicle" table="vehicles" schema="tcm">
<id name="id" type="integer" column="id">
<generator class="sequence">
<param name="sequence">tcm.vehicles_id_seq</param>
</generator>
</id>
.
.
.
<set name="devices" table="vehicle_device"
inverse="false" lazy="true" fetch="select" cascade="all" >
<key>
<column name="vehicle_id" not-null="true" />
</key>
<many-to-many entity-name="hibernate.entity.Device">
<column name="device_id" not-null="true" />
</many-to-many>
</set>
</class>
执行条件以获取所需'device imei'的结果时
@Override
public Vehicle getVehicleByDeviceImei(String imei) {
Criteria criteria = getSession().createCriteria(Vehicle.class);
criteria.createAlias("devices", "devices").add(Restrictions.eq("devices.imei", imei));
Vehicle v = (Vehicle) criteria.uniqueResult();
return v;
}
一切正常,除了生成的查询没有为第一个内连接中的链接表'vehicle_device'添加模式'tcm'
select .
.
.
.
from
tcm.vehicles this_
inner join
vehicle_device devices3_
on this_.id=devices3_.vehicle_id
inner join
devices devices1_
on devices3_.device_id=devices1_.id
where
devices1_.device_imei=?
并出错: 错误:关系“vehicle_device”不存在 第17行:vehicle_device devices3_
如果我将手动架构添加到生成的查询 - &gt; 'tcm.vehicle_device'它的工作原理。 如何修复我的配置,以便Hibernate Criteria为表'vehicle_device'添加模式。
答案 0 :(得分:0)
我解决了问题。我刚刚在映射
中的set标签中添加了scheme ='tcm'