Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
3.0.5
I have defined a lazy many-to one relationship between two entities.
(Street and Municipality). Multiple streets can point to a single municipality.
however when I search for the root entity i.e Street, it also loads the child entity i.e Municipality!
My hibernate configuration for Street has following mapping for Municipality:
<many-to-one name="municipality" class="Municipality" column="ID_MUNICIPALITY_TB" not-found="ignore" lazy="true" cascade="evict" insert="false" update="false"/>
The java code to build the criteria is as follows:
Code:
Criteria ct1 = session.createCriteria(Street.class);
ct1.createCriteria("municipality")
.add(Restrictions.eq("id","123"));
ct1.addOrder(Order.asc("id"));
ct1.setFirstResult(page);
ct1.setMaxResults(100);
The SQL query that gets executed is
select * from ( select this_.ID as ID1_, this_.VERSION as VERSION15_1_, this_.UPDATED_TS as UPDATED3_15_1_, this_.CREATED_TS as CREATED4_15_1_, this_.CREATED_BY as CREATED5_15_1_, this_.UPDATED_BY as UPDATED6_15_1_, this_.DELETED as DELETED15_1_, this_.FICTIONAL as FICTIONAL15_1_, this_.ID_MUNICIPALITY_TB as ID9_15_1_, municipali1_.ID as ID0_, municipali1_.VERSION as VERSION9_0_, municipali1_.UPDATED_TS as UPDATED3_9_0_, municipali1_.CREATED_TS as CREATED4_9_0_, municipali1_.CREATED_BY as CREATED5_9_0_, municipali1_.UPDATED_BY as UPDATED6_9_0_, municipali1_.FICTIONAL_FLAG as FICTIONAL7_9_0_, municipali1_.DELETED as DELETED9_0_, municipali1_.POST_CODE as POST9_9_0_, municipali1_.ID_COUNTRY_TB as ID10_9_0_ from LOC_STREET_TB this_ inner join LOC_MUNICIPALITY_TB municipali1_ on this_.ID_MUNICIPALITY_TB=municipali1_.ID where municipali1_.ID=? order by this_.ID asc ) where rownum <= ?
Can anyone suggest if there is something wrong with the configuration mapping?