hibernate5快速入门

好久没有关注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>	


hibernate.cfg.xml,用的dtd,还是3.0版本的。另外,创建sessionFactory的代码变了

		// 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知识交流,期待你的加入。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值