gpt4 book ai didi

java - with-clause 引用了 hSQL 中两个不同的 from-clause 元素

转载 作者:行者123 更新时间:2023-12-02 05:02:18 32 4
gpt4 key购买 nike

获取异常:

With-clause referenced two different from-clause elements

使用以下实体执行以下查询时:

@Entity
public class A {

@Id
private Long id;

@Column(name = "A_ID")
private Long aId;

@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "A_ID")
private B b;
}

@Entity
public class B {

@Id
private Long id;

@OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL)
@JoinColumn(name="C_ID" , referencedColumnName="ID")
private List<C> c;
}

@Entity
public class C {

@Id
private Long id;

@Column(name="C_ID")
private Long cId;

@Column
private String addType;
}

我的 HQL 查询是:

SELECT * FROM A a 
INNER JOIN a.b b ON a.aId=b.id
LEFT OUTER JOIN b.c c ON b.id=c.cId AND c.addType='PermanentAddress'
LEFT OUTER JOIN b.c d ON b.id=d.cId AND d.addType='ResidentialAddress'
LEFT OUTER JOIN b.c e ON b.id=e.cId AND e.addType='OfficeAddress'
WHERE a.id =:id

我得到的异常(exception)是:

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: with-clause referenced two different from-clause elements at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:91) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final] at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:109) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:284) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:206) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final] at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:126) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final] at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:88) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final] at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final] at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final] at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final] at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1800) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final] at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:328) ~[hibernate-entitymanager-4.3.6.Final.jar:4.3.6.Final] ... 187 common frames omitted

最佳答案

您的查询中不需要 ON 子句。 Hibernate 会自动链接模型。

关于java - with-clause 引用了 hSQL 中两个不同的 from-clause 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27957856/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com