好久没有关注hibernate了,最早使用过3.2版本,后来就没有再用过了。无意中看到hibernate版本都到5了。近日闲来无事,再温习下。
再次声明,本篇文章,只是简单的入门,来源于官方文档。希望能够到帮助别人。我用的版本是5.0.12。顺便说下为什么选择这个版本,我看官方上有5.0.12这个版本。最新的是5.2.10。两者都是稳定版本。再看下时间,5.0.12是在2017-01-19发布的。到现在也有几个月的时候了。决定还是用它吧。最新的不代表是最好的,另外,太新的话,估计资料也不一定全。最终选择了5.0.12。
官方下载地址
http://hibernate.org/orm/downloads/
下载完以后,我把它解到了D:\document\hibernate-release-5.0.12.Final目录下。本文章来源于
file:///D:/document/hibernate-release-5.0.12.Final/documentation/orm/5.0/quickstart/html/index.html的说明,文件来源于
D:\document\hibernate-release-5.0.12.Final\project\documentation\src\main\asciidoc\quickstart\tutorials\basic\src\test
以下是我的代码。建了个项目,maven方式,POM里添加
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.12.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
// A SessionFactory is set up once for an application!
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure() // configures settings from hibernate.cfg.xml
.build();
try {
sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
}
catch (Exception e) {
// The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
// so destroy it manually.
StandardServiceRegistryBuilder.destroy( registry );
}
就写这么多吧,剩下的自己看代码去吧。我提交到了git上,地址是:https://git.oschina.net/hnzmdpan/hibernate.git
hibernate新特性
参考文章:http://blog.youkuaiyun.com/qwe6112071/article/details/51010636
http://blog.youkuaiyun.com/xiangzhihong8/article/details/54171302
最后,我建了个 QQ群622539266,java知识交流,期待你的加入。