读书人

(二)hibernate annotations使用

发布时间: 2012-10-26 10:30:59 作者: rapoo

(2)hibernate annotations使用

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高很多.

读书人网 >软件架构设计

热点推荐