Hibernate DDL表动态创建 [英] Hibernate DDL table Dynamic creation

查看:212
本文介绍了Hibernate DDL表动态创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个spring引导项目,我使用hibernate将我的实体映射到数据库,但是现在我有了一个新的需求:我需要能够在数据库中动态创建表,而不需要任何映射(到目前为止)。

有谁知道一些框架,以帮助我解决这个问题:
- 我想执行SQL或类似的(ddl)来创建我的表
- 我需要处理连接管理



我已经被告知有关spring数据,但我需要对此有一些看法。



例如:
想象一下,我有一项服务可供客户使用,例如:

  class DBHACKService {
void executeSQL(String ddl)。

$ / code>

客户端会调用它:

  new DBHackService.executeSQL(create table mytable(name varchar)); 

在这个方法中,我可以对sql进行一些操作。
问题是:哪一个是将它发送给DBEngine的最好方法。



再次感谢

在此先感谢。
rui

解决方案

您可以看看 DdlUtils ,您可以随时随时根据需要在运行时进行更改,并将更改反映在数据库中。这种格式是独立于数据库的,所以你不必担心自己的可移植性。



我不知道它是多么的新。



如果您喜欢 Groovy


I've a spring boot project, and I'm using hibernate to map my entities to DB, However now I have a new requirement: I need to be able to dynamically create tables in DB, without any mapping (so far).

Does anyone know about some framework, to help me to deal with this: -I want to execute SQL or similar(ddl) to create my tables -I need to deal with connection management

I've been told about spring-data, but I need some opinion about this.

An example: Imagine I have a service available to client, for example:

class DBHACKService {
  void executeSQL(String ddl).
}

The client invoke this like :

new DBHackService.executeSQL ("create table mytable (name varchar)");

In this method I can do some manipulation to the sql. The question is: which is the best way to send it to DBEngine.

Thanks again

Thanks in advance. rui

解决方案

You can have a look at DdlUtils where one can feed it at any time with the changes you need at runtime and have your changes reflected on the DB. The format is database-independent so you won't have to worry about portability yourself.

I do not know how up to date it is though.

If you fancy Groovy.

这篇关于Hibernate DDL表动态创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆