在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>
- <mapping class="com.james.business.modle.domain.Event" />
之前使用xml配置内容为:
xml 代码
- <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
分享到:
相关推荐
该zip包含 hibernate3.3.2相关jar与文档,hibernate annotation3.3.4相关jar与文档。
在hibernate中使用annotation的demo
hibernate annotation中文文档
hibernate annotation hibernate3
学习JPA——Hibernate_Annotation使用实例学习JPA——Hibernate_Annotation使用实例学习JPA——Hibernate_Annotation使用实例
hibernate annotation 中文文档
hibernate中文APIhibernate annotation 中文API
现在我们公司在做web项目的时候,已经不用*.hbm.xml这种映射文件了,都是用Annotation(注解)方式来完成实体与表之间的映射关系,这样看起来比用xml文件来映射更具有可读性,自我感觉以后Hibernate Annotation的...
SpringMVC Spring Hibernate 框架整合 Annotation Maven Project
hibernate 注解 annotation 教程
Struts2+Spring2+Hibernate3+Annotation所需JAR包
Hibernate Annotation
3.尽管通常使用 <mapping> 元素来声明持久性类,您还是需要在 Hibernate 配置文件(通常是 hibernate.cfg.xml)中声明持久性类。 在使用 Hibernate Annotation 时,需要注意以下几点: * Hibernate Annotation 库...
hibernate-annotations相关的jar包
hibernate helloword annotation version
逐渐的Hibernate Annotation的映射方式也越来越盛行,相信过不了多久有可能会取代*.hbm.xml映射方式
Hibernate_3.2.0_Reference_zh_CN.chm hibernate_annotation.chm
Hibernate annotation 3.4 api CHM
hibernate中文的annotation使用说明,网上截下来的,希望对你有用