<div class="articalTag" id="sina_keyword_ad_area">
<table>
<tbody><tr>
<td class="blog_tag">
<script>
var $tag='杂谈';
var $tag_code='c3b59be0bc51e7ddf6d543341d9e23d8';
var $r_quote_bligid='7751c2440100xhgy';
var $worldcup='0';
var $worldcupball='0';
</script>
<span class="SG_txtb">标签:</span>
<h3><a href="http://search.sina.com.cn/?c=blog&q=%D4%D3%CC%B8&by=tag" target="_blank">杂谈</a></h3>
</td>
<td class="blog_class">
</td>
</tr>
</tbody></table>
</div>
<!-- 正文开始 -->
<div id="sina_keyword_ad_area2" class="articalContent ">
<p>今天遇到一个问题<font face="微软雅黑">两个表用HQL语句进行左右连接,前提是不是两个表需要有主外键关系?</font><br>
答案是不一定的,只要在hibernate的影射文件写好关系就行
例如:我有两张表
1.场次价格表Price_Showtime
名称 | 字段名 | 数据类型 | 长度 | 约束 |
编号 | psid | int | 11 | Not null,unique |
场次编号 | sid | int | 11 | |
时间 | time | datetime | | |
价格 | price | decimal | (10,2) | |
剩余票数 | ticket | int | 11 | |
总票数 | allticket | int | 11 | |
2.商品表Shopping
字段 | 字段中文名称 | 类型 | 长度 | 约束 |
sId | 商品编号 | int | 11 | 主键 |
sname | 商品名称 | nvarchar | 20 | 非空 |
psid | 场次价格编号 | | | 备注:如果是通票就为空 |
price | 原价 | decimal | (10,2) | |
Active_price | 活动价格 | decimal | (10,2) | |
number | 剩余数量 | int | 11 | |
allnumber | 总数量 | int | 11 | |
sexplain | 商品说明 | text | | |
notes | 注意事项 | text | | |
Active_starttime | 活动开始时间 | Datetime | | |
Active_endtime | 活动结束时间 | Datetime | | |
Use_starttime | 使用开始时间 | Datetime | | |
Use_endtime | 使用结束时间 | Datetime | 2 | |
Back_starttime | 活动倒数开始时间 | int | | |
sstatus | 商品状态 | Int | | 非空默认1可秒杀,0不可秒杀 |
spicture | 商品图片 | varchar | 255 | 存放路径 |
demoID | 预留字段 | int | 11 | 默认为空 |
stype | 类型 | int | | 如:0默认普通商品,1为秒杀,2为团购,3为竞拍 |
</div>
<!-- 正文结束 -->
<div id="share" class="shareUp">
<div class="share SG_txtb">
分享:
<div class="bshare-custom" style="display:inline;margin-left:5px;"><div class="bsPromo bsPromo2"></div><a title="分享到新浪微博" class="bshare-sinaminiblog" href="javascript:void(0);"></a><a title="分享到微信" class="bshare-weixin" href="javascript:void(0);"></a><a title="分享到QQ空间" class="bshare-qzone" href="javascript:void(0);"></a><a title="分享到豆瓣" class="bshare-douban" href="javascript:void(0);"></a><a title="更多平台" class="bshare-more bshare-more-icon more-style-addthis"></a>
</div>
</div>
<div class="up">
<div title="喜欢后让更多人看到" id="dbox_7751c2440100xhgy" class="upBox" style="cursor: pointer;">
<p ti_title="两个表用HQL语句进行左右连接,前提是不是两个表需要有主外键关系?" id="dbox2_7751c2440100xhgy" class="count" mnum="1">1</p>
<p class="link"><img width="15" height="15" align="absmiddle" src="https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif" class="SG_icon SG_icon34">喜欢</p>
</div>