Skip to content
Advertisement

Hibernate Join between 2 tables with foreign key

Im trying to get a list with results from join with two tables, but always get error. What i want is List with person and job name

  • Error

    • Cannot invoke “org.hibernate.hql.internal.ast.tree.FromElement.setAllPropertyFetch(boolean)” because “fromElement” is null
  • My tables

    • Person
      • int id
      • text name
      • int job_id (foreign key with table JOB(id))
    • Job
      • int id
      • text name
  • Entities

    JavaScript
    • DAO
    JavaScript

Advertisement

Answer

To be able to use left join in hql you should correct your mapping for Person in the following way:

JavaScript

and then you will be able to write hql query like this:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement