gpt4 book ai didi

java - 执行 JOIN 查询 Hibernate - 无法解析属性

转载 作者:行者123 更新时间:2023-12-01 09:57:26 26 4
gpt4 key购买 nike

我在 hibernate 中执行以下 JOIN 查询时遇到麻烦:

from proposal_evaluate_backoffice pab INNER JOIN pab.proposal pp INNER JOIN pab.analisys_backoffice ab where pp.sq_proposal = :sqProposal

其中“proposal_evaluate_backoffice”表将“proposal”和“analisys_backoffice”表引用为@JoinColumn > @ManyToOne注释

我收到以下错误:

org.hibernate.QueryException: could not resolve property: proposal of: com.skyautomate.model.Proposal_Evalaute_Backoffice [from com.skyautomate.model.Proposal_Evaluate_Backoffice pab INNER JOIN pab.proposal pp INNER JOIN pab.analisys_backoffice ab where pp.sq_proposal = :sqProposal]] with root cause org.hibernate.QueryException: could not resolve property: proposal of: com.skyautomate.model.Proposal_Evaluate_Backoffice

按照我的代码操作:

@Entity
@Table(名称=“proposal_evaluate_backoffice”)
公共(public)类 Proposal_Evaluate_Backoffice 实现可序列化 {

@Id
@ManyToOne
@JoinColumn(name="sq_proposal")
private Proposal sq_proposal;
@Id
@ManyToOne
@JoinColumn(name="sq_evaluate_backoffice")
private Evaluate_Backoffice sq_evaluate_backoffice;

我没有 Hibernate 的特定文件配置 (Hibernate.cfg.xml),但我已将所有配置放在“applicationContext.xml”中,因为我也使用 Spring MVC。

遵循我声明 bean 的 applicationContext.xml 文件的代码:

<!-- Hibernate 4 SessionFactory Bean definition -->
<beans:bean id="hibernate4AnnotatedSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="annotatedClasses">
<beans:list>
<beans:value>com.skyautomate.model.Proposal</beans:value>
<beans:value>com.skyautomate.model.Evaluate_Backoffice</beans:value>
<beans:value>com.skyautomate.model.Proposal_Evaluate_Backoffice</beans:value>
</beans:list>
</beans:property>
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect
</beans:prop>
<beans:prop key="hibernate.show_sql">true</beans:prop>
<beans:prop key="hibernate.default_schema">spweb</beans:prop>
</beans:props>
</beans:property>
</beans:bean>

有什么想法吗?

最佳答案

发生这种情况是因为提案字段的名称是 sq_proposal。您应该通过字段名称获取。

使用实体内部的定义将 HQL 转换为 SQL:实体的名称(From 子句)和其他子句的字段名称。

关于java - 执行 JOIN 查询 Hibernate - 无法解析属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37081934/

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