通过myEclipse创建hibernate的实体类

时间:2023-03-09 08:54:19

  今天有个新项目中需要使用到hibernate,刚好数据库表已经创建完毕,就顺便来总结一下通过myEclipse创建hibernate的实体类。

1..在myEclipse中选择MyEclipse Database Explorer视图→右键单击→new Databaes Driver→选择Driver template→(这里我选择使用Oracle(Thin driver))→输入名字Driver name:test→输入Connection URL(根据模版填入IP及端口jdbc:oracle:thin:@192.168.31.42:1521:ZDXS(这是我的))→输入User name→输入Password→选择Driver JARs(这里需要一个连接数据库的包ojdbc14.jar)→单击Test Driver测试连接→输入密码→ok→如果出现Datebase conection successfully established则连接成功→单击Finish创建。

通过myEclipse创建hibernate的实体类

通过myEclipse创建hibernate的实体类

如果出现Datebase conection successfully established则连接成功

通过myEclipse创建hibernate的实体类

单击Finish创建。

2.在myEclipse中选择java视图右键单击项目→mueclipse→add Hibernate Capabilities→选择Hibernate Specification:(在这里,我选择使用Hibernate 4.1版本)其他选择默认,→next→选择添加的位置→next→单击DB Driver→选择创建好的数据库连接,并且输入数据库密码→输入将实体添加的位置→Finish.

通过myEclipse创建hibernate的实体类

通过myEclipse创建hibernate的实体类

通过myEclipse创建hibernate的实体类

通过myEclipse创建hibernate的实体类

通过myEclipse创建hibernate的实体类

3.在myEclipse中选择MyEclipse Database Explorer视图→双击刚刚创建的数据库连接→打开数据库找到自己的工作空间选择TABLE→选择表(可以选择多张表)→右键单击Hibernate Reverse Engineering→选择实体类存放的位置,选择创建实体类→Finish

通过myEclipse创建hibernate的实体类

通过myEclipse创建hibernate的实体类

通过myEclipse创建hibernate的实体类

Finish创建完毕.

下面是创建之后的我的实体类。

通过myEclipse创建hibernate的实体类

在get,方法中有注解

通过myEclipse创建hibernate的实体类