当前位置: 代码迷 >> Java Web开发 >> hibernate多对一查询有关问题
  详细解决方案

hibernate多对一查询有关问题

热度:6601   发布时间:2013-02-25 21:08:59.0
hibernate多对一查询问题
有两个实体类,部门和职位,职位这个实体类里面有一个部门属性(也就是一个对象),我在职位表里面进行查询,选择了一个部门,但是把所有的部门都查询出来了,这是怎么回事?查询用的是criteria.add(Example.create(entity).enableLike());但是打印出来这么多的SQL语句:
Hibernate: 
  select
  * 
  from
  ( select
  this_.PID as PID2_0_,
  this_.POS_NAME as POS2_2_0_,
  this_.DID as DID2_0_ 
  from
  POSITION this_ 
  where
  (
  1=1
  ) 
  and this_.PID like ? 
  order by
  this_.PID asc ) 
  where
  rownum <= ?
Hibernate: 
  select
  department0_.DID as DID1_0_,
  department0_.DEP_NAME as DEP2_1_0_ 
  from
  DEPARTMENT department0_ 
  where
  department0_.DID=?
Hibernate: 
  select
  department0_.DID as DID1_0_,
  department0_.DEP_NAME as DEP2_1_0_ 
  from
  DEPARTMENT department0_ 
  where
  department0_.DID=?
Hibernate: 
  select
  department0_.DID as DID1_0_,
  department0_.DEP_NAME as DEP2_1_0_ 
  from
  DEPARTMENT department0_ 
  where
  department0_.DID=?
Hibernate: 
  select
  this_.PID as PID2_0_,
  this_.POS_NAME as POS2_2_0_,
  this_.DID as DID2_0_ 
  from
  POSITION this_ 
  where
  (
  1=1
  )
Hibernate: 
  select
  department0_.DID as DID1_0_,
  department0_.DEP_NAME as DEP2_1_0_ 
  from
  DEPARTMENT department0_ 
  where
  department0_.DID=?
Hibernate: 
  select
  department0_.DID as DID1_0_,
  department0_.DEP_NAME as DEP2_1_0_ 
  from
  DEPARTMENT department0_ 
  where
  department0_.DID=?
Hibernate: 
  select
  department0_.DID as DID1_0_,
  department0_.DEP_NAME as DEP2_1_0_ 
  from
  DEPARTMENT department0_ 
  where
  department0_.DID=?

怎么找出问题在哪儿?

------解决方案--------------------------------------------------------
把HQL 语句放到SQL 里面执行。 你就能找到是那个条错误,
  相关解决方案