1.在hibernate3.3.2的hibernate-annotations的兼容版本是3.4.0,可以到http://sourceforge.net下载
2.加入所需的包hibernate-annotations.jar,ejb3-persistence.jar,hibernate-commons-annotations.jar
3. 使用方法和ejb3.0一样.附件的官方帮助文档说得很明白
4.在hibernate.cfg.xml 加入被注解的实体类
<mapping resource="com/awf/hibernate/Student.hbm.xml"/> xml方式
<mapping class="com.awf.hibernate.Teacher"/> annotations方式
5.SessionFactory创建和xml方式的有点不一样,
SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
6.现在很多公司都开始用annotions方式,编写效率比xml高很多.
本文介绍了从hibernate3.3.2的hibernate-annotations版本升级到3.4.0的方法,包括引入所需包、使用方法与XML方式的对比,并强调了Annotations方式相较于XML方式在编写效率上的提升。

被折叠的 条评论
为什么被折叠?



