JPA 和 toplink create-table 如果它们尚不存在?
看来jpa是让我问很多问题的东西。
添加此功能后,
<property name="toplink.ddl-generation" value="create-tables"/>
我的 JPA 应用程序总是在运行时创建表,如果表已存在,这会导致异常。我希望 JPA 检查表是否已经存在,如果没有创建它们,但是我找不到上面执行此操作的属性的值。
因此,如果我只是将其关闭,是否有办法在某个时刻手动告诉 JPA 创建所有表?
异常
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'tags' already exists
Error Code: 1050
Call: CREATE TABLE tags (ID BIGINT AUTO_INCREMENT NOT NULL, NAME VARCHAR(255), OCCURRENCE INTEGER, PRIMARY KEY (ID))
更新这里是我得到MySQLSyntaxErrorException 的 ?!现在这肯定是错误的
Looks like jpa is something which makes me ask a lot of questions.
Having added this
<property name="toplink.ddl-generation" value="create-tables"/>
my JPA application always creates tables when running, which results in exceptions in case the tables already exist. I would like JPA to check if the tables already exist and if not create them, however I could not find a value for the property above which does this.
So if I just turn it off, is there a way to tell JPA manually at some point to create all the tables?
Update here's the exception I get
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'tags' already exists
Error Code: 1050
Call: CREATE TABLE tags (ID BIGINT AUTO_INCREMENT NOT NULL, NAME VARCHAR(255), OCCURRENCE INTEGER, PRIMARY KEY (ID))
MySQLSyntaxErrorException?! Now that's wrong for sure
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 http://www .oracle.com/technology/products/ias/toplink/JPA/essentials/toplink-jpa-extensions.html#Java2DBSchemaGen toplink没有更新现有表的选项,我不确定我是否会信任无论如何,它要做正确的事。
您可以配置 toplink 来生成一个 sql 脚本,然后您必须手动执行该脚本来创建所有表。文件名和位置可以这样配置:
According to http://www.oracle.com/technology/products/ias/toplink/JPA/essentials/toplink-jpa-extensions.html#Java2DBSchemaGen toplink does not have an option to update exiting tables, I'm not sure if I would trust it to do the right thing anyway.
You could configure toplink to generate a sql script that you then would have to execute manually to create all tables. The filenames and location can be configured like this:
奇怪的是,根据有关
toplink.ddl- Generation
扩展的 TopLink Essentials 文档,create-table
应保持现有表不变:Weird, according to the TopLink Essentials documentation about the
toplink.ddl-generation
extension,create-table
should leave existing table unchanged:Liquibase (http://www.liquibase.org) 擅长于此。完全适应它需要一些时间,但我认为这是值得的。
Liquibase 方式独立于您使用的 JPA 持久性提供程序。实际上,它甚至与数据库无关。
Liquibase (http://www.liquibase.org) is good at this. It takes some time to get fully used to it, but I think it's worth the effort.
The Liquibase-way is independent of which JPA persistence provider you use. Actually, it's even database agnostic.