站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2EE 专题hibernate达人请进,我们经理都解决不了的问题

hibernate达人请进,我们经理都解决不了的问题

摘要: hibernate达人请进,我们经理都解决不了的问题


我想把下述SQL语句转换成HQL语句(配置文件均已配好,但是有一个问题,
就是HQL语句中的“left outer join b.C c with c.date='2006-1-31'”)我在教程上看到用with可以添加join的条件,但是启动web服务时报错“org.hibernate.QueryException: unexpected token: with”,上网也搜不到,是不是hibernate的功能有限啊?

SQL:
select * from tableA a, tableB b
left join tableC c
on (b.id=c.id and c.date='2006-1-31')
where a.id=b.id and a.name='chy'

HQL:
from A a ,B b
left outer join b.C c with c.date='2006-1-31'
where a.id=b.id and a.name='chy'


from A a ,B b
left outer join b.C c
where a.id=b.id and a.name='chy' and c.date='2006-1-31'


学到!


这种方法我试过了,关键问题就在这里,如果c.date='2006-1-31'
写在where里就是先left join,后在连接后的表中筛选,而我的本意是先在c表中筛选,后将c表与a,b表做左连接,这两种方法的结果是截然不同的


是不是hibernate不支持join中加入条件呢?



难道没有人会吗?真的是hibernate不支持吧?


http://community.csdn.net/Expert/TopicView3.asp?id=5026822


Saro(这也不是江水,这是二十年流不尽的英雄血。谢谢!!我觉的你的方法没有问题,但是我在主表的中加入了
并加入


结果启动jboss时报错:
org.hibernate.MappingException: Could not read mapping document from file: D:/jboss-4.0.2/server/default...

Caused by: java.lang.NullPointerException
at org.hibernate.cfg.HbmBinder.parseFilter

我又试在子表中加入


可还是报错。

恳请指教!!


我又配置了一下:
主表:






子表:

column="measure_id" property-ref="measureId" not-null="true"/>







然后在publicDAO里:
String parm = "000000001";
hibernateTemplate.getSessionFactory().openSession().enableFilter("datefilter").setParameter("branchId",parm);
String hql = "from com.sihitech.biplatform.common.model.bo.MSfaRegisterBO";
List list = hibernateTemplate.find(hql);
现在服务不报错了,但是查出来发现数据没有经过筛选,好像filter没有用,是不是我哪里配错了?



↑返回目录
前一篇: 执行JAVA C:/javaSample.class后的问题
后一篇: 一个eclipse与hibernate的菜鸟问题(急)!