日期:2014-05-17  浏览次数:20658 次

使用注解的实体类如何加入到管理hibernate的spring配置文件中?
在使用hibernate的hbm.xml映射文件时,只需要在spring配置文件中加入 包名/xx.hbm.xml即可。
 
  但是现在我使用的是 @Entity注解了实体就没有写hbm.xml配置文件了。 再如何加入到spring配置文件中呢?

------解决方案--------------------
使用类名,sessionFactory的annotatedClasses属性如:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource"> 
<ref local="dataSource" />
</property>
<property name="annotatedClasses">
<list>
<value>com.abc.vo.Advertisement</value> 



</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>