2009.12.17(2)——hibernate传统xml写法和Annotation注解的写法
一.hibernate
在hibernate.cfg.xml里面
1.xml
2.annotation
直接写类
这个注意了 如果是这种写法 那么
二.spring+hibernate
在ApplicationContext.xml里面
1.xml
2.annonation
一.hibernate
在hibernate.cfg.xml里面
1.xml
<mapping resource="pojo/user.hbm.xml"/>
2.annotation
直接写类
<mapping class="pojo/User"/>
这个注意了 如果是这种写法 那么
Configuration cfg = new AnnotationConfiguration().configure()
不是我们以前的
Configuration cfg = new Configuration().configure()
二.spring+hibernate
在ApplicationContext.xml里面
1.xml
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<value>pojo/user.hbm.xml</value>
</property>
</bean>
2.annonation
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>pojo.User</value>
</list>
</property>
</bean>