`
Jameslyy
  • 浏览: 387683 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

在Hibernate中使用Annotation

阅读更多

在Hibernate中使用Annotation需要JDK 5.0的支持,Hibernate 3.2、Hibernate Annotations 3.2。

Hibernate 3.2中,hibernate3.jar是hibernate3的核心包,在lib中,antlr、dom4j、CGLIB、asm、Commons Collections、Commons Logging、 EHCache,Hibernate底层还需要Java Transaction API,所以还需要jta.jar。

Hibernate Annotations 3.2中,需要hibernate-annotations.jar、ejb3-persistence.jar。

把hibernate.cfg.xml中的映射配置改为:

xml 代码<mapping class="com.james.business.modle.domain.Event"></mapping>
  1. <mapping class="com.james.business.modle.domain.Event" />  

之前使用xml配置内容为:

xml 代码
  1. <mapping resource="com/james/business/modle/domain/Event.hbm.xml" />  

用org.hibernate.cfg.AnnotationConfiguration替代以前的org.hibernate.cfg.Configuration,来初始化org.hibernate.SessionFactory。

初始化方法,sessionFactory = new AnnotationConfiguration().configure() .buildSessionFactory();

如果这时使用sessionFactory = new Configuration().configure() .buildSessionFactory(),会报异常:An AnnotationConfiguration instance is required to use 。

 

参考:

http://blog.csdn.net/caterpillar_here/archive/2006/07/15/926642.aspx  林信良 Hibernate with annotation

http://www.spikesource.com/spikewatch.logs/fedora-3-i386/718/hibernate/reports/clover/org/hibernate/cfg/Configuration.html  Configuration class code

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics