why simple select query returns List but join query return List<Object> in jpa

前端 未结 3 1502
日久生厌
日久生厌 2021-01-20 16:09

I am using play framework with jpa. I have a model Jobads with 2 functions to findall() findByLocation()

My Model

  public class Job         


        
相关标签:
3条回答
  • 2021-01-20 16:31

    createQuery() method accepts two parameters, query and the type of the query result, thus you can write type safe query this way:

    createQuery("FROM Jobads j join j.city c WHERE c.name LIKE :location", Jobads.class);

    0 讨论(0)
  • 2021-01-20 16:32

    Think about what is returned by your second query : you will have a table with two rows due to the join statement. However, I don't really know what will be the type of the output in this case, try using getClass on it to see.

    0 讨论(0)
  • 2021-01-20 16:38

    It's happening because that's how HQL queries without a select clause work. Note that these are not valid JPQL queries. JPQL makes the select clause mandatory, and using a select clause would allow you to specify what you want the query to return:

    select j from Jobads j join j.city c WHERE c.name LIKE :location
    
    0 讨论(0)
提交回复
热议问题