jcsa February 2016

Path expected for join hibernate

I have a problem with hibernate HQL queries and simple INNER JOIN

String hql = "SELECT NEW es.criteria.crc.model.queryObjects.NameQuery(pf.name) FROM Person as p INNER JOIN PhisicalPerson as pf WHERE pf.idPersona = p.idPersona";
    return personService.query(hql);

My Java file has the following code:

public class NameQuery{
    private String name;

    public NameQuery(String name) {
        super();
        this.name= name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name= name;
    }
}

I recieve the following error in console:

   Caused By: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join!

Answers


v.ladynev February 2016

You need to have an association (@OneToMany, @OneToOne) between Person and PhisicalPerson. Having such an association you don't need the where clause

SELECT NEW es.criteria.crc.model.queryObjects.NameQuery(pf.name) 
    FROM Person as p INNER JOIN p.pf

In the example pf is a property of Person, associated to PhisicalPerson.

class Person {

    @OneToOne(mappedBy = "person")
    private PhisicalPerson pf;

}

class PhisicalPerson {

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fk_person")
    private Person person;

}

Post Status

Asked in February 2016
Viewed 1,526 times
Voted 7
Answered 1 times

Search




Leave an answer