生成与Hibernate 4的SQL数据库创建脚本

编程入门 行业动态 更新时间:2024-10-14 02:22:36
本文介绍了生成与Hibernate 4的SQL数据库创建脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们目前正在使用Hibernate 3,我们使用Hibernate工具生成的SQL脚本的DB模式。

We are currently using Hibernate 3 and we use Hibernate Tools to generate SQL scripts for the DB schema.

我们使用以下Ant任务

We use the following Ant task

<hibernatetool destdir="${target}"> <jpaconfiguration persistenceunit="@{persistenceUnit}" propertyfile="@{propertyfile}"/> <classpath refid="@{classpathid}"/> <!-- the file name is relative to $destdir --> <hbm2ddl outputfilename="@{output}" format="true" export="false" drop="false"/> </hibernatetool>

我们想切换到休眠4:我们如何才能达到类似的东西不用Hibernate的工具

We would like to switch to Hibernate 4: how can we achieve something similar without Hibernate tools?

推荐答案

您可以直接使用SchemaExport类来生成DDL脚本:

You can directly use the SchemaExport class to generate the DDL script :

Configuration config = new Configuration(); Properties properties = new Properties(); properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect"); properties.put("hibernate.connection.url", "jdbc:postgresql://localhost:5432/Test"); properties.put("hibernate.connection.username", "username"); properties.put("hibernate.connection.password", "password"); properties.put("hibernate.connection.driver_class", "org.postgresql.Driver"); properties.put("hibernate.show_sql", "true"); config.setProperties(properties); config.addAnnotatedClass(MyMappedPojo1.class); config.addAnnotatedClass(MyMappedPojo2.class); .................. SchemaExport schemaExport = new SchemaExport(config); schemaExport.setDelimiter(";"); /**Just dump the schema SQLs to the console , but not execute them ***/ schemaExport.create(true, false);

更多推荐

生成与Hibernate 4的SQL数据库创建脚本

本文发布于:2023-07-15 13:03:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1111386.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   数据库   Hibernate   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!