I have a problem with LocalSessionFactoryBean and AnnotationSessionFactoryBean,first I use LocalSessionFactoryBean as sessionFactory, and there are many hbm.xml files.like this:
Code:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean ">
<property name="mappingDirectoryLocations">
<list>
<value>classpath*:/XX/common/domain/hbm</value>
</list>
</property>
and now i am using AnnotationSessionFactoryBean ,and do not want modify so many java files,and want to use these hibernate xml files.and the sessionFactory like below:
Code:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="annotatedClasses">
<list>
<value>XX.XX.model.Resource</value>
</list>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath*:/XX/common/domain/hbm</value>
</list>
</property>
but in origin manager files there is a method
Code:
public List getAllItemcat(Integer provinceId){
return getHibernateTemplate().find(" from XX.common.domain.Itemcat
where provinceId="+provinceId+" order by itemcatId desc");
}
the hibernate sql become:
Code:
select itemcat0_.ITEM_CAT_ID as ITEM1_2_, itemcat0_.ITEM_CAT_NAME as ITEM2_2_,
itemcat0_.PROVINCE_ID as PROVINCE3_2_, itemcat0_.LANG_ID as LANG4_2_, itemcat0_.ZJ_ID as ZJ5_2_
from t_item_cat itemcat0_
where (provinceId=19 ) order by itemcatId desc
just said in the clause the provinceId and itemcatId can not become the table colunm name province_id and item_cat_it,and
in LocalSessionFactoryBean style it work correctly!
what is wrong with it?how should i do??
thanks a lot
ps:
when give alias to the entity,and the clause add the alias,it can run correctly
public List getAllItemcat(Integer provinceId){
return getHibernateTemplate().find(" from XX.common.domain.Itemcat a
where a.provinceId="+provinceId+" order by a.itemcatId desc");
}
but
"select new XX.domain.entity(a.id,a.name) from XX.common.domain.Itemcat a"
can not run correctly,I really do not know what is the wrong with it