java - JPA query join error: org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join -


i attempting join in following jpa query following error:

org.hibernate.hql.internal.ast.querysyntaxexception: path expected join! [from com.crm.entity.user user join fetch role role on role.user_id = user.id user.deleted = false , user.enabled = true , user.username = :username]

here implementation:

import javax.persistence.entitymanager; import javax.persistence.persistencecontext; import javax.persistence.query; import javax.transaction.transactional;  import org.springframework.stereotype.repository;  import com.crm.entity.user;  @transactional @repository public class userjpadaoimpl implements userjpadaocustom {      @persistencecontext     private entitymanager em;      @override     public user getuser(string username) {         query query = em.createquery("from user user "                                     + "join fetch role role on role.userid = user.id "                                     + "where user.deleted = false "                                     + "and user.enabled = true "                                     + "and user.username = :username", user.class);         query.setparameter("username", username);         return (user)query.getsingleresult();     }  } 

user entity:

@entity @table(name = "user") public class user extends baseentity implements userdetails, visible {      private static final long serialversionuid = 1l;      @column(name = "username")     private string username;      @column(name = "password")     private string password;      /* spring security fields*/     @onetomany     @joincolumn(name = "user_id")     private list<role> roles; ... 

role entity:

@entity @table(name = "role") public class role implements grantedauthority, identifiable {      private static final long serialversionuid = 1l;      @id     @generatedvalue(strategy = generationtype.identity)     @column(name = "id", unique = true, nullable = false)     private integer id;      @column(name = "name", nullable = false)     private string name;      @column(name = "user_id")     private integer userid; ... 

what wrong join in query?

it hql not sql:

   query query = em.createquery("from user user "                                 + "join fetch user.role "                                 + "where user.deleted = false "                                 + "and user.enabled = true "                                 + "and user.username = :username", user.class); 

you have work on object structure not on tables


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -