jpa - NamedQuery selectively define attributes -
i have namedquery in entity class defined
@namedquery(name = "emp.findall", query = " select new test.entity.emp(o.empno, o.salary, o.project) emp o ")
constructor
public emp(string empno, string salary, project project) { this.empno = empno; this.salary= salary; this.project = project; }
and generated sql is
select t0.emp_no, t0.salary, t1.project_id, t1.project_name, t1.project_desc emp t0, projects t1 (t1.project_id (+) = t0.project_id)
in namedquery how selectively declare projectid , projectname instead of attributes project class? wouldn't display attributes of project class in namedquery.
how can achieve this?
update 1
public emp(string empno, string salary, long projectid, string projectname) { project pr = new project(); this.empno = empno; this.salary= salary; pr.setprojectid = projectid; pr.setprojectname = projectname; }
try (and update constructor accordingly)
@namedquery(name = "emp.findall", query = " select new test.entity.emp(o.empno, o.salary, p.projectid, p.projectname) emp o inner join o.project p ")
constructor this
public emp(string empno, string salary, long projectid, string projectname) { this.empno = empno; this.salary= salary; project pr = new project(); pr.setprojectid(projectid); pr.setprojectname(projectname); this.project = pr; }
Comments
Post a Comment