问题是这样,一个终端对应着最后一次发送的信息,建了两个表 t_terminal t_gps_one ,如果这个终端没有发送过任何信息,那这个t_gps_one表应该是没有任何与它数据的
简单来讲就是实现hibernate的一对一双向关联,并且t_gps_one一边是可能为空的,最重要的一点是读取t_terminal表数据时要连同对应的t_gps_one数据一起取出来
我是这样设置的 t_terminal的hbm.xml
<one-to-one name="gpsOneVO" class="com.gxcs.model.GpsOneVO" constrained="false" cascade="delete" fetch="join"/> t_gps_one的hbm.xml
<many-to-one name="terminalVO" class="com.gxcs.model.TerminalVO" fetch="join" unique="true" not-found="ignore" cascade="none">
<column name="terminalId" not-null="true">
<comment>终端的ID,外键</comment>
</column>
</many-to-one>
读取的时候都是先select t_terminal然后再select t_gps_one, 能不能做到是直接像SQL一样left join一条语句来查询数据啊
查了很多hibernate的相关资料,都是说把constrained设置为true就自动是join形式,但问题是t_gps_one不一定有数据啊,就非inner join不可,不能left join吗
简单来讲就是实现hibernate的一对一双向关联,并且t_gps_one一边是可能为空的,最重要的一点是读取t_terminal表数据时要连同对应的t_gps_one数据一起取出来
我是这样设置的 t_terminal的hbm.xml
<one-to-one name="gpsOneVO" class="com.gxcs.model.GpsOneVO" constrained="false" cascade="delete" fetch="join"/> t_gps_one的hbm.xml
<many-to-one name="terminalVO" class="com.gxcs.model.TerminalVO" fetch="join" unique="true" not-found="ignore" cascade="none">
<column name="terminalId" not-null="true">
<comment>终端的ID,外键</comment>
</column>
</many-to-one>
读取的时候都是先select t_terminal然后再select t_gps_one, 能不能做到是直接像SQL一样left join一条语句来查询数据啊
查了很多hibernate的相关资料,都是说把constrained设置为true就自动是join形式,但问题是t_gps_one不一定有数据啊,就非inner join不可,不能left join吗
解决方案 »
- org.springframework.beans.factory.BeanDefinitionStoreException,请各位大虾,看看是什么错误,谢谢!
- SSi整合 struts中的Action调用几次之后就找不到了,高手给说说
- web.xml 中 初始化参数中的param-value,相对路径如何写?
- 怎样把数据赋值到extjs的grid
- FTP问题
- hibernate中Session的load出的问题
- [求助]我用STRUTS做的搜寻页面不能查询条件值不能为中文?
- 吐血求教:weblogic+Oracle数据库连接池的配置问题!
- 晕~IDEA又TM报错~实在是无力了~~~
- oracle动态sql问题求解,希望大牛指点指点
- tomcate 启动不了
- tomcat运行出现异常
<one-to-one name="gpsOneVO" class="com.gxcs.model.GpsOneVO" cascade="delete" property-ref="terminalVO"/> t_gps_one的hbm.xml
<many-to-one name="terminalVO" class="com.gxcs.model.TerminalVO" unique="true" not-found="ignore" cascade="none">
<column name="terminalId" not-null="true">
<comment>终端的ID,外键</comment>
</column>
</many-to-one>
其次代码可以这样写: session.createQuery("from TerminalVO t left join fetch t.gpsOneVO where ...");
确实是少了property-ref="terminalVO" 没有这个是取不到gps_one的数据的,谢谢