One-root-entity-per-returned-row phenomenon of hibernate
2007-05-16 14:39
148 查看
public static List t() ...{
List r = new ArrayList();
Session s = Sf.getSession();
Transaction tx;
tx = s.beginTransaction();
String sql;
try ...{
r = s.createCriteria(JtsUser.class)
.add(Restrictions.idEq(2))
.setFetchMode("jtsHistories", FetchMode.JOIN)
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
.list();
tx.commit();
} catch (Exception e) ...{
e.printStackTrace();
tx.rollback();
} finally ...{
s.close();
}
return r;
}
public static List tt() ...{
List r = new ArrayList();
Session s = Sf.getSession();
Transaction tx;
tx = s.beginTransaction();
String sql;
try ...{
r = s.createCriteria(JtsUser.class)
.add(Restrictions.idEq(2))
.setFetchMode("jtsHistories", FetchMode.JOIN)
.list();
tx.commit();
} catch (Exception e) ...{
e.printStackTrace();
tx.rollback();
} finally ...{
s.close();
}
return r;
}
t().size() is 1; While tt().size() is 4, that's the one-root-entity-per-returned-row phenomenon of hibernate.
Add "setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)" to eliminate the one-root-entity-per-returned-row phenomenon that you're seeing.
相关文章推荐
- mybatis ---- 级联查询 一对多 (集合映射)mybatis中:returned more than one row, where no more than one was expected
- org.hibernate.StaleStateException: Batch update returned unexpected row count
- Result consisted of more than one row
- what is the difference of select single and select up to one row in abap
- hibernate 的many to one 的问题IllegalArgumentException occurred while calling setter of hibernatePOJO
- No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
- #One paper per week# MAP: Microblogging Assisted Profiling of TV Shows
- Hibernate 级联查询: More than one row with the given identifier was found 报错
- Hibernate 异常:“@OneToOne or @ManyToOne on XXX references an unknown entity: XXX”
- org.hibernate.StaleStateException: Batch update returned unexpected row count
- mybatis中:returned more than one row, where no more than one was expected.异常
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [cn.facekee.cms.entity.CmsFansgroup#195]
- Result consisted of more than one row
- Using two asp:ButtonColumns in one row of datagrid
- Hibernate:More than one row with the given identifier was found解决办法
- Hibernate:Batch update returned unexpected row count from update [0]; actual row count: 0; expected:
- hibernate 报错: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 解决方法
- Mysql报错:Result consisted of more than one row
- org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actua
- org.hibernate.HibernateException: More than one row with the given identifier was found: 116, for cl