Home Owner of the fetching not present
Reply: 1

Owner of the fetching not present

ghostrider
1#
ghostrider Published in 2018-02-11 08:29:58Z

I am trying to learn hibernate here and came across this Class:

HelloWorldClient.java

public class HelloWorldClient {
public static void main(String[] args) {

EntityManagerFactory emf = 
Persistence.createEntityManagerFactory("hello-world");
EntityManager em = emf.createEntityManager();
EntityTransaction txn = em.getTransaction();
try {
txn.begin();
Query query = em.createQuery("select student from Guide guide join fetch 
guide.students student");
List<Student> students = query.getResultList(); 
System.out.println(students);
    txn.commit();           
    } catch (Exception e) {
        if (txn != null) {
            txn.rollback();
        }
        e.printStackTrace();
    } finally {
        if (em != null) {
            em.close();
        }
    }

}
}

While executing the query I am getting the error:

java.lang.IllegalArgumentException: org.hibernate.QueryException: query 
specified join fetching, but the owner of the fetched association was not 
present in the select list [FromElement{explicit,not a collection join,fetch 
join,fetch non-lazy properties,classAlias=student,role=entity.Guide.students,tableName=Student,tabl
eAlias=students1_,origin=Guide guide0_,columns={guide0_.id ,className=entity.Student}}] [select student from entity.Guide guide join fetch 
 guide.students student]at Impl.java:294)
at client.HelloWorldClient.main(HelloWorldClient.java:31)

The Student and the guide have a many to one relationship..

Manish Kumar
2#
Manish Kumar Reply to 2018-02-11 09:47:38Z

Try guide at place of student as

select guide from Guide guide join fetch guide.students student

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.322142 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO