Hibernate的HQl语句集锦

[size=large]Hibernate---HQL[/size]

[size=medium]1、多表左连接:[/size]

String hql = "select count(*) " +
" from SysMsgUserLink a " +
" left join a.sysMsg b " +
" left join a.sysRevUser c " +
" left join a.sysSendUser d " +
" where ... ";


[size=medium]2、左连接加子查询:[/size]
String hql = "select count(*) " +
" from SysMsgUserLink a " +
" left join a.sysMsg b " +
" left join a.sysRevUser c " +
" left join a.sysSendUser d " +
" where ... " +
" and a.linkId in(" +
" select a.linkId " +
" from SysMsgUserLink a " +
" where ... ";



[size=medium]注意的关键点:
1、进行左连接的两张表在建立Model层时,就必须注解清楚其关联,否则会报 “无法识别该属性”的错误
2、其实跟sql是一样的用法,只是将数据库中的表名直接换成对象名称即可[/size]

你可能感兴趣的:(WEB框架)