java - 使用 Hibernate 创建架构(表)

标签 java

我有一个 jar 文件,其中有一组注释为 @Entity 的模型。现在我想在数据库中创建与 jar 文件中的模型相对应的表(我可以通过在本地存储库上安装 jar 来使用 jar 文件作为 pom 文件中的依赖项)。它应该是通用的(例如 MySQL、Postgresql、oracle、ms sql server、h2...)。我是 hibernate 新手。任何人都可以建议我如何做到这一点。

最佳答案

在 org.hibernate.tool.hbm2ddl.SchemaExport 的帮助下我们可以完成这个任务。
示例:

Configuration configuration = new Configuration();
//we can set property here e.g configuration.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");.....
configuration = configuration.configure();
SchemaExport schemaExport  = new SchemaExport(configuration);
schemaExport.create(false, true); //1st parameter indicated to show query on console and 2nd parameter is to create(update) table in database. 

关于java - 使用 Hibernate 创建架构(表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25147052/

相关文章:

java - 为 Playframework 2.3x 生成基于 UUID 的 @ID

java - 通过for循环在字符串中插入字符

Java如何添加一个排除特定数字的随机生成器?

java - 如何使用正则表达式测试 URL 是否包含某些参数但不包含其他参数

java - 如何始终以完整的十进制格式而不是科学记数法显示 BigDecimal 对象?

java - Jersey UnmarshalException JAXB,带有多个 getEntity() 的 XML

java - 未绑定(bind)的类路径变量

java - 错误 : requestLocationUpdate GPS provider

java - 用不确定的 ProgressBar 替换 ActionBar 菜单项图标

java - 如何比较2个LinkedHashMap并获得键和值的差异?