我在Jboss 5.1中使用Hibernate EntityManager 3.4.0.GA。但是尽管在我的 mysql 控制台中查询似乎工作正常。我收到以下错误
SQL状态 S0022原因:javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: 无法执行查询原因:java.sql.SQLException:找不到列"代码"。
我有两个表,一个是带有字段 id、代码、类型的站点,另一个是描述可能组合的 manyToMany 表
+------------+--------+--------+
| ID | | type | code |
+------------+--------+--------+
| 1 | AP | LAX |
| 2 | AP | JFK |
| 3 | AP | LHR |
| 4 | AP | MAN |
+------------+--------+--------+
+------------+--------+--------+
| depStationId | destStationId |
+------------+--------+--------+
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 3 | 1 |
+------------+--------+--------+
我的本机查询被调用是
select d.code as origin, a.code as destination from DepDest dd
inner join STATIONS d on dd.depStationId=d.id and d.type=?1
inner join STATIONS a on dd.destStationId=a.id and a.type=?2
这似乎与查询中的双左 joisn 和相同的列名有关。我已经找到了这个亲戚,但仍然没有解决方法。
https://hibernate.onjira.com/browse/HHH-3988
任何人都可以建议解决方法吗谢谢
你试过做子查询吗?
select d.code as origin, a.code as destination
from (
select dd.destStationId, d.code DepDest dd
inner join STATIONS d on dd.depStationId=d.id and d.type=?1) d
inner join STATIONS a on d.destStationId=a.id and a.type=?2