如果执行 DDL 语句出错,则使 EcliseLink 失败
我们使用 EclipseLink 进行持久化,并通过将属性 eclipselink.ddl- Generation
设置为 drop-and-create-tables
来配置 EclipseLink 自动创建数据库表等。 。
这工作正常,但是 EclipseLink(以及我们的应用程序)将在单元测试期间以及实际 Web 应用程序启动时愉快地继续,即使某些 DDL 语句失败。
当我错误地使用 @Index
注释时,我注意到了这一点,并想知道为什么没有创建索引,直到我在日志中注意到:
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.h2.jdbc.JdbcSQLException:
Column "MY_INDEX_FLD" not found; SQL statement:
CREATE INDEX X_INDEX ON X (MY_INDEX_FLD)
我真的想知道是否会发生这种情况。如果某些 DDL 语句失败,是否有某种方法告诉 EclipseLink 将其设为致命错误?
在这种情况下,我希望至少让我们的(JUnit)集成测试失败。
如果错误只是表已经存在(在针对现有数据库进行测试的情况下),则可以通过某种方式忽略该错误。
We use EclipseLink for persistence, and have configured EclipseLink to automatically create the database tables etc., by setting the property eclipselink.ddl-generation
to drop-and-create-tables
.
This works fine, however EclipseLink (and thus our app) will merrily continue during unit tests, and on actual web app startup even if some of the DDL statements failed.
I noticed this when I incorrectly used the @Index
annotation, and wondered why the index was not created, until I noticed in the logs:
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.h2.jdbc.JdbcSQLException:
Column "MY_INDEX_FLD" not found; SQL statement:
CREATE INDEX X_INDEX ON X (MY_INDEX_FLD)
I really want to know if this happens. Is there some way to tell EclipseLink to make it a fatal error if some DDL statements fails?
I'd like to at least have our (JUnit) integration tests fail in this case.
Bonus points for some way to be able to ignore if the error is simply that the tables are already there (in the case of testing against an existing database).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然,EclipseLink 无法做到这一点。
我查看了 EclipseLink 中创建表的方法:
(在 页)。
我包含这些行:
所以显然 EclipseLink 假设表(和索引)创建期间的错误总是由已经存在的表引起:-(。
我为此提交了 EclipseLink bug:错误 356068。
Apparently, EclipseLink cannot do this.
I had a look at the method in EclipseLink that creates tables:
(search for "createTables" on the page).
I contains the lines:
So apparently EclipseLink assumes that errors during table (and index) creation are always caused by the table already existing :-(.
I filed an EclipseLink bug for this: Bug 356068.