开发者

Make EcliseLink fail if there is an error executing the DDL statements

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 开发者_JAVA百科are already there (in the case of testing against an existing database).


Apparently, EclipseLink cannot do this.

I had a look at the method in EclipseLink that creates tables:

org.eclipse.persistence.tools.schemaframework.TableCreator.createTables()

(search for "createTables" on the page).

I contains the lines:

        try {
            schemaManager.createObject(table);
            session.getSessionLog().log(SessionLog.FINEST,
                "default_tables_created", table.getFullName());
        } catch (DatabaseException ex) {
            session.getSessionLog().log(SessionLog.FINEST,
            "default_tables_already_existed", table.getFullName());
                if (!shouldIgnoreDatabaseException()) {
                    throw ex;
                }
        }

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜