在eclipse环境中使用hibernateTools自动生成实体类

使用eclipse从数据库生成实体类:

1首先要在eclipse中安装hibernate tools 插件,可以使用菜单help-eclipse marketplace,也可以使用help-install new software;推荐使用前者,用起来方便,不用到处去找正确的url。

2在eclipse中建立数据源连接Connection profile:菜单windows-showView-DataSourceExplorer,右击DatabaseConnection新建Connection profile
3在项目中生成hibernate配置文件:hibernate.cfg.xml,其中只配了一个<session-factory>
4在run-hibernateCodeGeneration-hibernateCodeGenerationConfigrations新建代码生成的配置;

勾选reverse engineer from jdbc connection从jdbc链接反向设计;

output directory 选择资源文件根目录;package定义一个包名,这个包会被自动创建出来,创建在output directory指定的目录

注意: outpur directory 不要指定了具体的包,否则生成的代码中导包会导错

在exporters输出标签页中勾选上实体类和xml映射;


5运行新建的hibernateCodeGenerationConfigrations配置

菜单run-hibernateCodeGeneration-刚才新建的代码生成配置

-------------------------------------

Connection profile;

连接配置:需要指定数据库名,Connection profile可以轻松复制(右击duplicate);

SQl scrapbook;

SQL剪切板:可以再此处执行sql命令:右击execute all会在sql result面板中显示结果,且可以将sql保存在项目中,这样一来还需要下载额外的数据库客户端工具吗?

hibernateCodeGenerationConfigrations;

自动生成代码的配置

原文地址:https://www.cnblogs.com/afraidToForget/p/6510549.html