0

Jboss5.1でHibernateEntityManager3.4.0.GAを使用しています。しかし、私のmysqlコンソールでは、クエリは正常に機能しているようです。次のエラーが発生します

sqlstate s0022原因:javax.persistence.PersistenceException:org.hibernate.exception.SQLGrammarException:クエリを実行できませんでした原因:java.sql.SQLException:列'コード'が見つかりません。

2つのテーブルがあります。1つはフィールドid、code、typeを持つStationで、もう1つは可能な組み合わせを説明する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

誰かが回避策を提案できますかありがとう

4

1 に答える 1

0

サブクエリを実行してみましたか?

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
于 2012-06-25T12:39:10.353 に答える