0
此查詢不再用於工作。 (我切換到註釋,這是兩個破剩餘試驗之一。)帶連接表的休眠HQL
我有三個表:
+---------------+
| Competition |
+---------------+
| competitionId |
| . . . |
+---------------+
+---------------+
| Competitor |
+---------------+
| competitorId |
| . . . |
+---------------+
+------------------------+
| CompetitionCompetitors |
+------------------------+
| competitionId |
| competitorId |
+------------------------+
和代碼/查詢使用工作是
Query query = session.createQuery(
"select c.id from Competition c join c.competitors co where co.id = :competitorId");
query.setParameter("competitorId", competitor.getCompetitorId());
List list = query.list();
下面是一些前面的SQL日誌記錄從休眠到來,再加上錯誤信息:
Hibernate: update db.competition set competitorId=? where competitionId=?
Hibernate: update db.competition set competitorId=? where competitionId=?
Hibernate: update db.competition set competitorId=? where competitionId=?
17:12:49,232 WARN JDBCExceptionReporter:233 - SQL Error: 1054, SQLState: 42S22
17:12:49,240 ERROR JDBCExceptionReporter:234 - Unknown column 'competitorId' in 'field list'
(得承認,我很驚訝地看到發生在一個查詢更新)。
這裏的註釋在競爭:
@OneToMany(targetEntity = Competition.class)
@JoinColumn(name = "competitorId")
private Set<Competitor> competitors = new TreeSet<Competitor>();
我是怎麼了效果也很糟糕?
非常瞭解映射和JPA。謝謝!這使查詢工作。 – Marvo