Department对象有
private int id;
private String name;
Set <Employee> emps;
Employee对象有
private int id;
private String name;
private Department department;使用hql: from Department d left join fetch d.emps这条语句查出来的数据有重复数据
比如一个department有两个employee的数据时,查出来是两个department和department其下的两个employee,两个department数据是完全一样的,这个是怎么一回事
private int id;
private String name;
Set <Employee> emps;
Employee对象有
private int id;
private String name;
private Department department;使用hql: from Department d left join fetch d.emps这条语句查出来的数据有重复数据
比如一个department有两个employee的数据时,查出来是两个department和department其下的两个employee,两个department数据是完全一样的,这个是怎么一回事
解决方案 »
- 整合Shiro+SpringMVC的一个问题
- 继续散分
- 请问如何拼接sql语句,实现动态绑定sql
- STRUTS2.1.6 get方式传参中文乱码问题
- 各位大大们,救救我,给我点建议我想培训,不知道上哪去
- 关于axis2客户端调用的问题
- 新手急求救:Io 异常: The Network Adapter could not establish the connection.
- struts2显示list的问题
- 在线等:Tomcat 5下配置Oracle Connection Pool的小问题,急~
- 为什么 ServletContextListener 不受spring管理
- oracle数据插入的问题:ORA-32109: invalid column or parameter position
- sx:datetimepicker日期问题
<id name="id">
<generator class="native"></generator>
</id>
<property name="name" /> <set name="emps" inverse="true" >
<key column="depart_id"></key>
<one-to-many class="Employee" />
</set> </class>
</hibernate-mapping>
<hibernate-mapping
package="com.hibernate.entity"> <class name="Employee">
<id name="id" >
<generator class="native"></generator>
</id>
<property name="name" />
<many-to-one name="department" column="depart_id" class="Department" >
</many-to-one>
</class>
</hibernate-mapping>配置的文件的关系是上面的,能指出哪里有问题才导致这样重复的数据出现吗
加个show_sql配置看看sql就知道了,不细讲了。
HQL可以这样写,不会重复了。
select distinct d from Department d left join fetch d.emps
from Department.
看有没重复的~