如何在Mysql中使用jpa在hibernate 4中动态添加列? [英] how to add a column dynamically in hibernate 4 with jpa in Mysql?

查看:190
本文介绍了如何在Mysql中使用jpa在hibernate 4中动态添加列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用spring mvc4 hibernate4和Mysql构建一个电子商务网站,当应用程序已经运行且服务器不应该重新启动时,管理员应该能够动态地将列添加到特定的表中。例如,如果在表1中插入一个新值,然后在表2中为它创建一个列。


  1. 有什么办法可以配置hibernate 4与JPA动态
    在运行时添加一列?

  2. 如果是的话,你能给我一个示例代码?

  3. 如果没有实现我的目标
    动态添加列的替代方法是什么?


您需要使用JDBC和普通SQL进行此操作并使用DDL语句。



我想知道你的用例是什么?


I am currently building a e-commerce website using spring mvc4 hibernate4 and Mysql where the Admin should be able to dynamically add a column to a particular table when the application is already running and the server should not be restarted.For example if a new value is inserted in table 1 then a column should be created for it in table 2.

  1. Is there any way to configure hibernate 4 with JPA to dynamically add a column at runtime?
  2. And if yes can you give me a sample code?
  3. And if no what are the alternate ways of achieving my goal of dynamically adding columns?

解决方案

I think there can be no JPA/Hibernate solution for this, since your Entities map to your database schema and what you are trying to achieve is simultanously mutating your Entity's Class and the corresponding schema. You need to go with JDBC and plain SQL for this and use DDL statements.

I wonder what's your use case for this?

这篇关于如何在Mysql中使用jpa在hibernate 4中动态添加列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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