Hibernate version: 2.1.8 vs. 3.0
Mapping documents: Can add if needed.
Code between sessionFactory.openSession() and session.close():
Code:
Criteria criteria = ThreadSession.getSession().createCriteria(RoleMenuItem.class)
.add(Expression.eq("role", role.getDAO()))
.add(Expression.or(Expression.eq("read",Boolean.TRUE),
Expression.or(Expression.eq("delete",Boolean.TRUE),Expression.eq("addUpdate",Boolean.TRUE))))
.setFetchMode("menuItem",FetchMode.EAGER)
.createCriteria("menuItem")
.setFetchMode("parent",FetchMode.EAGER);
if(parent == null){
criteria.add(Expression.isNull("parent"));
} else {
criteria.add(Expression.eq("parent",parent));
}
list = criteria.list();
Name and version of the database you are using: DB2 7.1
The generated SQL (show_sql=true):
version 2.1.8:
Hibernate: select this.ID as ID2_, this.ADD_UPDATE as ADD_UPDATE2_, this.DELETED as DELETED2_, this.MENU_ITEM as MENU_ITEM2_, this.ROLE as ROLE2_, this.READ as READ2_, this.CREATED_DATE as CREATED_7_2_, this.CREATED_BY as CREATED_BY2_, this.CHANGED_DATE as CHANGED_9_2_, this.CHANGED_BY as CHANGED_BY2_, this.JSI_KEY as JSI_KEY2_, x0_.ID as ID0_, x0_.ACCESS_KEY as ACCESS_KEY0_, x0_.ACTION as ACTION0_, x0_.ADD_UPDATE as ADD_UPDATE0_, x0_.ALTIMAGE as ALTIMAGE0_, x0_.DELETED as DELETED0_, x0_.DESCRIPTION as DESCRIPT7_0_, x0_.HEIGHT as HEIGHT0_, x0_.IMAGE as IMAGE0_, x0_.LOCATION as LOCATION0_, x0_.NAME as NAME0_, x0_.ONCLICK as ONCLICK0_, x0_.ONMOUSEROUT as ONMOUSE13_0_, x0_.ONMOUSEOVER as ONMOUSE14_0_, x0_.PAGE as PAGE0_, x0_.PARENT as PARENT0_, x0_.READ as READ0_, x0_.TARGET as TARGET0_, x0_.TITLE as TITLE0_, x0_.TOOLTIP as TOOLTIP0_, x0_.WIDTH as WIDTH0_, x0_.HAS_COUNT as HAS_COUNT0_, x0_.LINK_TITLE as LINK_TITLE0_, x0_.CREATED_DATE as CREATED24_0_, x0_.CREATED_BY as CREATED_BY0_, x0_.CHANGED_DATE as CHANGED26_0_, x0_.CHANGED_BY as CHANGED_BY0_, x0_.JSI_KEY as JSI_KEY0_, menuitem2_.ID as ID1_, menuitem2_.ACCESS_KEY as ACCESS_KEY1_, menuitem2_.ACTION as ACTION1_, menuitem2_.ADD_UPDATE as ADD_UPDATE1_, menuitem2_.ALTIMAGE as ALTIMAGE1_, menuitem2_.DELETED as DELETED1_, menuitem2_.DESCRIPTION as DESCRIPT7_1_, menuitem2_.HEIGHT as HEIGHT1_, menuitem2_.IMAGE as IMAGE1_, menuitem2_.LOCATION as LOCATION1_, menuitem2_.NAME as NAME1_, menuitem2_.ONCLICK as ONCLICK1_, menuitem2_.ONMOUSEROUT as ONMOUSE13_1_, menuitem2_.ONMOUSEOVER as ONMOUSE14_1_, menuitem2_.PAGE as PAGE1_, menuitem2_.PARENT as PARENT1_, menuitem2_.READ as READ1_, menuitem2_.TARGET as TARGET1_, menuitem2_.TITLE as TITLE1_, menuitem2_.TOOLTIP as TOOLTIP1_, menuitem2_.WIDTH as WIDTH1_, menuitem2_.HAS_COUNT as HAS_COUNT1_, menuitem2_.LINK_TITLE as LINK_TITLE1_, menuitem2_.CREATED_DATE as CREATED24_1_, menuitem2_.CREATED_BY as CREATED_BY1_, menuitem2_.CHANGED_DATE as CHANGED26_1_, menuitem2_.CHANGED_BY as CHANGED_BY1_, menuitem2_.JSI_KEY as JSI_KEY1_ from ROLE_MENU_ITEM this inner join MENU_ITEM x0_ on this.MENU_ITEM=x0_.ID left outer join MENU_ITEM menuitem2_ on x0_.PARENT=menuitem2_.ID where this.ROLE=? and (this.READ=? or (this.DELETED=? or this.ADD_UPDATE=?)) and x0_.PARENT=? as expected.
version 3.0.2:
Hibernate: update MENU_ITEM set PARENT=null where PARENT=?
Hibernate: select this_.ID as ID2_, this_.ADD_UPDATE as ADD2_207_2_, this_.DELETED as DELETED207_2_, this_.MENU_ITEM as MENU4_207_2_, this_.ROLE as ROLE207_2_, this_.READ as READ207_2_, this_.CREATED_DATE as CREATED7_207_2_, this_.CREATED_BY as CREATED8_207_2_, this_.CHANGED_DATE as CHANGED9_207_2_, this_.CHANGED_BY as CHANGED10_207_2_, this_.JSI_KEY as JSI11_207_2_, menuitem1_.ID as ID0_, menuitem1_.ACCESS_KEY as ACCESS2_205_0_, menuitem1_.ACTION as ACTION205_0_, menuitem1_.ADD_UPDATE as ADD4_205_0_, menuitem1_.ALTIMAGE as ALTIMAGE205_0_, menuitem1_.DELETED as DELETED205_0_, menuitem1_.DESCRIPTION as DESCRIPT7_205_0_, menuitem1_.HEIGHT as HEIGHT205_0_, menuitem1_.IMAGE as IMAGE205_0_, menuitem1_.LOCATION as LOCATION205_0_, menuitem1_.NAME as NAME205_0_, menuitem1_.ONCLICK as ONCLICK205_0_, menuitem1_.ONMOUSEROUT as ONMOUSE13_205_0_, menuitem1_.ONMOUSEOVER as ONMOUSE14_205_0_, menuitem1_.PAGE as PAGE205_0_, menuitem1_.PARENT as PARENT205_0_, menuitem1_.READ as READ205_0_, menuitem1_.TARGET as TARGET205_0_, menuitem1_.TITLE as TITLE205_0_, menuitem1_.TOOLTIP as TOOLTIP205_0_, menuitem1_.WIDTH as WIDTH205_0_, menuitem1_.HAS_COUNT as HAS22_205_0_, menuitem1_.LINK_TITLE as LINK23_205_0_, menuitem1_.CREATED_DATE as CREATED24_205_0_, menuitem1_.CREATED_BY as CREATED25_205_0_, menuitem1_.CHANGED_DATE as CHANGED26_205_0_, menuitem1_.CHANGED_BY as CHANGED27_205_0_, menuitem1_.JSI_KEY as JSI28_205_0_, menuitem4_.ID as ID1_, menuitem4_.ACCESS_KEY as ACCESS2_205_1_, menuitem4_.ACTION as ACTION205_1_, menuitem4_.ADD_UPDATE as ADD4_205_1_, menuitem4_.ALTIMAGE as ALTIMAGE205_1_, menuitem4_.DELETED as DELETED205_1_, menuitem4_.DESCRIPTION as DESCRIPT7_205_1_, menuitem4_.HEIGHT as HEIGHT205_1_, menuitem4_.IMAGE as IMAGE205_1_, menuitem4_.LOCATION as LOCATION205_1_, menuitem4_.NAME as NAME205_1_, menuitem4_.ONCLICK as ONCLICK205_1_, menuitem4_.ONMOUSEROUT as ONMOUSE13_205_1_, menuitem4_.ONMOUSEOVER as ONMOUSE14_205_1_, menuitem4_.PAGE as PAGE205_1_, menuitem4_.PARENT as PARENT205_1_, menuitem4_.READ as READ205_1_, menuitem4_.TARGET as TARGET205_1_, menuitem4_.TITLE as TITLE205_1_, menuitem4_.TOOLTIP as TOOLTIP205_1_, menuitem4_.WIDTH as WIDTH205_1_, menuitem4_.HAS_COUNT as HAS22_205_1_, menuitem4_.LINK_TITLE as LINK23_205_1_, menuitem4_.CREATED_DATE as CREATED24_205_1_, menuitem4_.CREATED_BY as CREATED25_205_1_, menuitem4_.CHANGED_DATE as CHANGED26_205_1_, menuitem4_.CHANGED_BY as CHANGED27_205_1_, menuitem4_.JSI_KEY as JSI28_205_1_ from ROLE_MENU_ITEM this_ inner join MENU_ITEM menuitem1_ on this_.MENU_ITEM=menuitem1_.ID left outer join MENU_ITEM menuitem4_ on menuitem1_.PARENT=menuitem4_.ID where this_.ROLE=? and (this_.READ=? or (this_.DELETED=? or this_.ADD_UPDATE=?)) and menuitem1_.PARENT=?
Basically in 2.1.8, when the criteria.list() line is reached, the select runs just fine, but in 3.0.2 an update is run first. This update sets the parent to null before running the select, so the select is always empty. Why would the criteria.list() call set the parent to null??? Any insight would be helpful. Also, in 3.0.2 the FetchMode.EAGER is changed to FetchMode.JOIN.
TIA
Dan