Java EE / JPA将新表/实体添加到数据库的方法 [英] Java EE/JPA way to add new tables/entities to database

查看:187
本文介绍了Java EE / JPA将新表/实体添加到数据库的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mysql数据库,我想添加向数据库添加新表的功能。我可能很容易找到这个JPQL的例子,但是我如何自动为这个新表生成实体,以便我可以在我的JPA代码的其余部分中引用它来更新和从表中删除我通常引用实体不是实际的表本身。

I have a mysql database that I want to add the functionality of adding a new table to the database. I could probably easily find the example of the JPQL for this but how would I then automatically generate the entity for this new table so that I could reference it in the rest of my JPA code for updating and deleting from the table I usually reference the entity not the actual table itself.

我现在使用的实体我已经使用eclipe从我创建的表中生成了。但是在部署之后我们显然不会让Eclipse这样做,因此我们需要在每次创建表时自动完成。

The Entities I have now I've used eclipe to generate from the tables I created. But after deployment we obviously won't have Eclipse to do this so we need it done automatically every time a table is created.

推荐答案

动态创建和映射新表不是JPA支持的。它需要动态创建新的Java类并动态更新映射元数据。您可以使用JDBC或本机查询执行所需的一切。但也许您应该解释为什么需要动态创建新表。

Creating and mapping new tables dynamically is not something that JPA supports. It would need creating new Java classes on the fly and dynamically update the mapping metadata. You can do everything you want with JDBC or native queries. But maybe you should explain why you need to create new tables on the fly.

这篇关于Java EE / JPA将新表/实体添加到数据库的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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