spring ssh整合中,对hibernate的映射文件是怎么配置的?
<list>
<value>com/ssh/entity/Employee.hbm.xml</value>
</list>
</property>
假设使用的是注解版配置的Employee,怎么写? 展开
———————— 两种方式:
<!-- 基于注解创建的SessionFactory对象 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<!-- 第一种方式:依次配置每个实体类 -->
<property name="annotatedClasses">
<list>
<value>com.ssh.entity.Employee</value>
</list>
</property>
<!-- 第二种方式:配置实体类所在的包 -->
<property name="annotatedPackages">
<list>
<value>com.ssh.entity</value>
</list>
</property>
</bean>
2024-11-19 广告
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="entityInterceptor">
<ref local="entityInterceptor" />
</property>
<property name="dataSource">
<ref bean="bmsdataSource" />
</property>
<property name="mappingLocations">
<list>
<value>classpath:/cn/edu/ynu/Test.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
com.huateng.hibernate.dialect.HTOracle9Dialect
</prop>
<!--
<prop key="hibernate.show_sql">true</prop>
-->
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
</props>
</property>
</bean>
例如你所有的实体都在com.ssh.model 下面
那么value ="com.ssh.model"
这里用的sessionFactory不在是org.springframework.orm.hibernate3LocalSessionFactoryBean
而是 org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean