ozsenegal
ozsenegal

Reputation: 4133

Execute JOIN query Hibernate - could not resolve property

I'm facing trouble to do follow JOIN query in hibernate:

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

Where "proposal_evaluate_backoffice" table references "proposal" and "analisys_backoffice" tables as @JoinColumn > @ManyToOne annotations

Im getting follow error:

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

Follow my code:

@Entity @Table(name="proposal_evaluate_backoffice") public class Proposal_Evaluate_Backoffice implements Serializable {

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

I don't have an specific file config for Hibernate (Hibernate.cfg.xml), but i've put all configuration together in "applicationContext.xml", since i'm using Spring MVC as well.

Follow code of applicationContext.xml file where I declared beans:

<!-- 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>

Any ideas?

Upvotes: 1

Views: 1985

Answers (1)

aviad
aviad

Reputation: 1573

This happens because proposal field's name is sq_proposal. You should fetch by the field name.

HQL is translated to SQL using the definitions lying inside the entity: the entity's name (From clause) and fields names for the other clauses.

Upvotes: 2

Related Questions