Good day
Here is my DTO class:
package com.comp.model.employee.hierarchy;
import javax.ejb.Stateful;
import javax.persistence.ColumnResult;
import javax.persistence.ConstructorResult;
import javax.persistence.NamedNativeQuery;
import javax.persistence.SqlResultSetMapping;
import java.io.Serializable;
import java.util.Objects;
@NamedNativeQuery(
name = "PartialHierarchyDisplay",
query = "SELECT t.emp_aid, t.supervisor_emp_aid, t.level, t.branch, t.pos "
+ "FROM connectby('human_resources.emp_info', 'emp_aid', 'emp_supervisor', 'emp_last_name', :empAid, 0, '~') "
+ "t(emp_aid bigint, supervisor_emp_aid bigint, level integer, branch text, pos integer)", resultSetMapping = "PartialHierarchyDisplay"
)
@SqlResultSetMapping(
name = "PartialHierarchyDisplay",
classes = @ConstructorResult(
targetClass = PartialHierarchyDisplay.class,
columns = {
@ColumnResult(name = "emp_aid"),
@ColumnResult(name = "supervisor_emp_aid"),
@ColumnResult(name = "level"),
@ColumnResult(name = "branch"),
@ColumnResult(name = "pos")
}
)
)
@Stateful
public class PartialHierarchyDisplay implements Serializable {
private static final long serialVersionUID = 1L;
private Long empAid;
private Long supervisorEmpAid;
private Integer level;
private String branch;
private Integer pos;
public PartialHierarchyDisplay(Long empAid, Long supervisorEmpAid, Integer level, String branch, Integer pos) {
this.empAid = empAid;
this.supervisorEmpAid = supervisorEmpAid;
this.level = level;
this.branch = branch;
this.pos = pos;
}
public Long getEmpAid() {
return empAid;
}
public void setEmpAid(Long empAid) {
this.empAid = empAid;
}
public Long getSupervisorEmpAid() {
return supervisorEmpAid;
}
public void setSupervisorEmpAid(Long supervisorEmpAid) {
this.supervisorEmpAid = supervisorEmpAid;
}
public Integer getLevel() {
return level;
}
public void setLevel(Integer level) {
this.level = level;
}
public String getBranch() {
return branch;
}
public void setBranch(String branch) {
this.branch = branch;
}
public Integer getPos() {
return pos;
}
public void setPos(Integer pos) {
this.pos = pos;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PartialHierarchyDisplay that = (PartialHierarchyDisplay) o;
return Objects.equals(empAid, that.empAid) &&
Objects.equals(supervisorEmpAid, that.supervisorEmpAid) &&
Objects.equals(level, that.level) &&
Objects.equals(branch, that.branch) &&
Objects.equals(pos, that.pos);
}
@Override
public int hashCode() {
return Objects.hash(empAid, supervisorEmpAid, level, branch, pos);
}
@Override
public String toString() {
return "PartialHierarchyDisplay{" +
"empAid=" + empAid +
", supervisorEmpAid=" + supervisorEmpAid +
", level=" + level +
", branch='" + branch + '\'' +
", pos=" + pos +
'}';
}
}
And this is the service class:
package com.comp.controller.employee.hierarchy;
import com.comp.utility.DmlSQL;
import com.comp.model.employee.hierarchy.PartialHierarchyDisplay;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.io.Serializable;
import java.util.List;
@SuppressWarnings({"WeakerAccess", "unused"})
@Stateless
public class PartialHierarchyService implements Serializable {
private static final long serialVersionUID = 1L;
@PersistenceContext(unitName = "PostgresDS")
private transient EntityManager em;
@EJB
private transient DmlSQL dmlSQL;
public List<PartialHierarchyDisplay> getPartialHierarchy(Long empAid) {
List<PartialHierarchyDisplay> partialHierarchyList = em
.createNamedQuery("PartialHierarchyDisplay")
.setParameter("empAid", empAid)
.getResultList();
return partialHierarchyList;
}
}
I followed Vlad’s tutorial from here:
I am using Wildfly-11 which in turn uses Hibernate 5.1.10.Final
My problem is that this piece of code:
.createNamedQuery("PartialHierarchyDisplay")
Causes IntelliJ 18.1.1 to show an error with detail:
Cannot resolve query ‘PartialHierarchyDisplay’
What am I doing wrong here?
Sincerest thanks in advance for any assistance.