eclipse下怎么搭建hibernate5.0环境

  介绍

这篇文章给大家分享的是有关eclipse下怎么搭建hibernate5.0环境的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

具体如下:

<李>

hibernate引入的jar包:hibernate-release-5.0.12.Final.zip

<李>

数据库驱动:mysql-connector-java-5.1.46

<强>二。安hibernate插装件

打开eclipse,点击帮助——在eclipse市场,如图输入:hibernate工具,再点击果按钮,找到JBoss工具

 eclipse下怎么搭建hibernate5.0环境

点击安装安装

 eclipse下怎么搭建hibernate5.0环境

如图选择hibernate工具,点击Confrm安装。安装完成后重启eclipse。

<强>三。创建工程

1。创建新项目hibernateDemo,在工程下建立自由文件夹。打开jar包的目录,导入lib/要求下的和数据库的jar包,添加到构建路径

 eclipse下怎么搭建hibernate5.0环境

在src下新建文件

 eclipse下怎么搭建hibernate5.0环境

点击下,默认文件名,点击下,如图配置数据库信息

 eclipse下怎么搭建hibernate5.0环境

选择utf - 8编码方式,点击完成,生成的hibernate.cfg。xml配置文件内容如下

& lt; ? xml  version=?.0“,编码=癠TF-8" ?比;   & lt; ! DOCTYPE  hibernate-configuration 公众   ,,,,,//Hibernate/Hibernate  Configuration  DTD  3.0//EN"   ,,,“http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"比;   & lt; hibernate-configuration>   & lt;才能session-factory>   ,,,& lt; property  name=癶ibernate.connection.driver_class"祝辞com.mysql.jdbc.Driver   ,,,& lt; property  name=癶ibernate.connection.password"祝辞a123   ,,,& lt; property  name=癶ibernate.connection.url"在jdbc: mysql://localhost: 3306/tb_test   ,,,& lt; property  name=癶ibernate.connection.username"祝辞sherman   ,,,& lt; property  name=癶ibernate.dialect"祝辞org.hibernate.dialect.MySQLDialect   ,,,,   ,,,,   & lt;才能/session-factory>   & lt;/hibernate-configuration>

注意,把& lt;会话工厂名称=癕ySQL"比;的名字属性去掉,否则报org.hibernate.engine.jndi。JndiException异常,在该文件中添加一些配置,如图:

& lt; ? xml  version=?.0“,编码=癠TF-8" ?比;   & lt; ! DOCTYPE  hibernate-configuration 公众   ,,,,,//Hibernate/Hibernate  Configuration  DTD  3.0//EN"   ,,,“http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"比;   & lt; hibernate-configuration>   & lt;才能session-factory>   ,,,& lt; property  name=癶ibernate.connection.driver_class"祝辞com.mysql.jdbc.Driver   ,,,& lt; property  name=癶ibernate.connection.password"祝辞a123   ,,,& lt; property  name=癶ibernate.connection.url"在jdbc: mysql://localhost: 3306/tb_test   ,,,& lt; property  name=癶ibernate.connection.username"祝辞sherman   ,,,,   ,,,& lt; !——,配置数据库方言,——比;   ,,,& lt; property  name=癶ibernate.dialect"祝辞org.hibernate.dialect.MySQL5Dialect   ,,,& lt; !——,控制台打印sql语句,——比;   ,,,& lt; property  name=皊how_sql"祝辞true   ,,,& lt; !——,格式化sql ——比;   ,,,& lt; property  name=癴ormat_sql"祝辞true   ,,,& lt; !——在启动时根据配置更新数据库,——比;   ,,,& lt; property  name=癶ibernate.hbm2ddl.auto"祝辞update   ,,,& lt; !——,配置连接池的连接数,——比;   ,,,& lt; property  name=癱onnection.pool_size"在20 & lt;/property>   ,,,,   ,,,& lt; !——,注册实体映射类,——比;   ,,,& lt; mapping 类=癱om.gdut.app.entity.News"/比;   & lt;才能/session-factory>   & lt;/hibernate-configuration>

在src下新建一个包com.gdut.app。实体,存放持久化类新闻,新闻类代码如下

package  com.gdut.app.entity;      import  javax.persistence.Entity;   import  javax.persistence.GeneratedValue;   import  javax.persistence.GenerationType;   import  javax.persistence.Id;   import  javax.persistence.Table;      @ entity   @ table (name=癗EWS_INFO")   public  class  News  {   @ id   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

eclipse下怎么搭建hibernate5.0环境