Hibernate 中注释配置有何用处?
我之前使用过 AnnotationConfiguration
但现在已弃用
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass(Product.class);
factory = cfg.buildSessionFactory();
所以现在建议使用 Configuration
安装,但仍然会出现一些错误: 。
现在如何构建会话工厂?
I used AnnotationConfiguration
before but now is deprecated
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass(Product.class);
factory = cfg.buildSessionFactory();
So now it's recommended to use Configuration
insted, but still get some error:
.
How build a session factory now ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么您正在使用一些相当新的版本,也许是 4.0.0.CR4?如果是这样,请检查 buildSessionFactory 的 Javadoc,它会告诉您以下信息:
尽管不知道建议替换是否有效,但从未使用过它。
So you are using some pretty new version, 4.0.0.CR4 perhaps? If so, then check the Javadoc of buildSessionFactory and it will tell you following:
No idea though is suggested replacement working, never used it.
据我所知,org.hibernate.cfg.Configuration.buildSessionFactory() 并未被弃用:
http://docs.jboss.org/hibernate/core/3.5/javadoc/org/hibernate/cfg/Configuration.html#buildSessionFactory()
http://www.docjar.com/html/api/org/hibernate/cfg/Configuration.java.html
http://docs.jboss.org/hibernate/core/3.6/quickstart/en-US/html_single/
您确定不仅仅是 Eclipse 漏报吗?
org.hibernate.cfg.Configuration.buildSessionFactory() is not deprecated as far as I can see :
http://docs.jboss.org/hibernate/core/3.5/javadoc/org/hibernate/cfg/Configuration.html#buildSessionFactory()
http://www.docjar.com/html/api/org/hibernate/cfg/Configuration.java.html
http://docs.jboss.org/hibernate/core/3.6/quickstart/en-US/html_single/
Are you sure it's not just Eclipse that's miss-reporting?