今天遇到一个非常奇怪的问题,mysql数据库,hibernate注解配置表,
from Wxyhdtb where zt=1 and wxyh.id=1 order by wxyh.id
测试发现在where条件中wxyh.id会出错,Unknown column 'wxyh.id' in 'where clause',但是只在order by wxyh.id却没有问题 ,请问这是什么情况?
注:以前用oracle 就不会出现这种情况
hql在mysql中查询出错
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
oxcow 2015-09-06 09:33关注from Wxyhdtb where zt=1 and wxyh.id=1 order by wxyh.id
HQL语句面向的是对象bean. 虽然看起来很想SQL,但其实是对象。 因此对于你的这条HQL语句。 Wxyhdtb应对应类,同时where 后的字段对应的应该是Wxyhdtb对象的属性。看你的HQL where条件,Wxyhdtb 应该 和 wxyh 对应的对想是有关联的。 wxyh应该对应另一个表的。
针对
from Wxyhdtb where zt=1 and wxyh.id=1 order by wxyh.id
这条HQL语句,你的实体bean可能如下结构
@Entity @Table(name = "tb_a") class Wxyhdtb{ @Id Long id; Integer zt ; @OneToOne // 也有可能是 ManyToOne Wxyh wxyh; } @ Entity @Table(name = "tb_b") class Wxyh { @Id Long id; }解决 无用评论 打赏 举报