0
내 서버 측 구성 요소는 JPA와 함께 EJB입니다. 엔티티HQL 쿼리가 예상대로 작동하지 않습니다.
@Embeddable
public class EmployeeId implements java.io.Serializable {
private static final long serialVersionUID = 4542369821217566566L;
@Column(name = "emp_id")
private Integer empId;
@Size(max = 10)
private String name;
public EmployeeId() {
}
public Byte getEmpId() {
return this.empId;
}
public void setEmpId(Integer empId) {
this.empId = empId;
}
public String getName() {
return this.stationId;
}
public void setName(String name) {
this.name = name;
}
}
내 테이블이
직원
과 같은 임베디드@Entity
@Table(name = "employee")
public class Employee implements Serializable {
private static final long serialVersionUID = 4235645698986231545L;
@EmbeddedId
private EmployeeId id;
@Column
private String designation;
public Employee() {
}
public EmployeeId getId() {
return this.id;
}
public void setId(EmployeeId id) {
this.id = id;
}
public String getDesignation() {
return this.designation;
}
public void setDesignation(String designation) {
this.designation = designation;
}
}
을 따를
내 법인 보인다
========
emp_id | name | designation |
==============|==============
1001 | xxxx | programmer |
1001 | yyyy | programmer |
1002 | zzzz | tester |
1003 | aaaa | HR |
1004 | bbbb | Admin |
1005 | cccc | Manager |
1006 | dddd | programmer |
1007 | eeee | programmer |
1008 | ffff | programmer |
1008 | gggg | programmer |
=============================
내 JPQL 쿼리는 내 예상 결과는 다음과 같다
String query = "from Employee where designation = :design ";
public List<Employee> find(String designation) {
return getEntityManager().createQuery(query).setParameter("design", designation).getResultList();
}
입니다. 나는이 동안 수동으로
emp_id | name | designation |
==============|==============
1001 | xxxx | programmer |
1001 | yyyy | programmer |
1006 | dddd | programmer | 6 rows
1007 | eeee | programmer |
1008 | ffff | programmer |
1008 | gggg | programmer |
=============================
조회 수 그러나 내가 받고 있어요는
emp_id | name | designation |
==============|==============
1001 | xxxx | programmer |
1001 | xxxx | programmer | 6 rows
1001 | xxxx | programmer |
1001 | xxxx | programmer |
1001 | xxxx | programmer |
1001 | xxxx | programmer |
=============================
이 왜 중복 값 만 행의 정확한 수를주고있다 JPQL 출력을 통해 무엇입니까? 문제는 어떻게 해결할 수 있습니까?
http://en.wikibooks.org/wiki/Java_Persistence/JPQL#Select_query_examples 여기에 어떤 문제를보고하지 않습니다. 루프 내부에서 첫 번째 결과를 계속해서 인쇄하지 않도록하십시오. –
그것은 JPQL이 아닌 HQL입니다. 차이점이 있습니다. 그리고 HQL을 사용하는 경우 JPQL이 아니기 때문에 질문을 Hibernate로 태그를 지정하십시오. – DataNucleus