Search code examples
mysqlhibernatenamed-query

Create namedQuery! i don't know how it create


I have this select:

SELECT name,surname,role, height, age, nazov_typu, nazov, body 
from users 
join type on type.idTYPE=users.type_idtype and users.team_idteam=?  
join  rola on rola.idROLA=users.rola_idROLA 
join status on status.idSTATUS= users.STATUS_idSTATUS

Could you help me with creating namedQuery?


Solution

  • This should be the Query

    @Entity 
    @NamedQuery(name ="userQuery",query="SELECT u From User u,Type t,Rola r,Status s WHERE r.rolaId=u.rolaId AND t.typeId=u.typeId and u.teamId=:teamId")
    public class User {...
    

    I am assuming that you have other entities available with you like Type Rola and Status. If not and you don't want to create other entities. You can use Native named Query, where you can set the column into this User Entity.