如何在新版本的Hibernate中初始化注释配置实例?

时间:2013-09-01 08:39:05

标签: java hibernate annotations hibernate-4.x hibernate3

我正在使用hibernate-release-4.2.4.Final版本并尝试使用注释而不是hbm.xml文件。但是在运行时,它总是抛出an-annotation-configuration-instance-is-required-to-use-error

当我尝试导入org.hibernate.AnnotationConfiguration时,它显示该类已被弃用。然后我尝试从hibernate-annotation.jar复制Annotation配置类文件并在hibernate3.jar中使用它并且它工作正常。我的问题是如何在较新版本的Hibernate版本中初始化注释配置实例?

1 个答案:

答案 0 :(得分:0)

在Hibernate4中,您不应再使用AnnotationConfiguration,而是使用Configuration。使用HibernateUtils或其他会话工厂构建器来构建会话工厂。您可以找到here这样的实用程序示例。