从Hibernate迁移JPA项目后,我遇到了很多这样的例外:
Aug 31, 2015 4:00:52 PM org.eclipse.persistence.session.file:/var/folders/ls/0vdttqm92zq1rtcsjntc4mxw0000gn/T/gfembed8285464623855636118tmp/applications/salonea-1.0/WEB-INF/classes/_LocalServicesMySQL_JTA
WARNING:
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') REFERENCES ()' at line 1
Error Code: 1064
Call: ALTER TABLE provider ADD CONSTRAINT fk_provider_corporation FOREIGN KEY () REFERENCES ()
Query: DataModifyQuery(sql="ALTER TABLE provider ADD CONSTRAINT fk_provider_corporation FOREIGN KEY () REFERENCES ()")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:900)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:962)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:631)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2002)
at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeNoSelectCall(DatasourceCallQueryMechanism.java:271)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeNoSelect(DatasourceCallQueryMechanism.java:251)
at org.eclipse.persistence.queries.DataModifyQuery.executeDatabaseQuery(DataModifyQuery.java:85)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:899)
at org.eclipse.persistence.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:3214)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1786)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1737)
at org.eclipse.persistence.internal.sessions.AbstractSession.priviledgedExecuteNonSelectingCall(AbstractSession.java:5008)
at org.eclipse.persistence.tools.schemaframework.TableDefinition.createForeignConstraintsOnDatabase(TableDefinition.java:891)
at org.eclipse.persistence.tools.schemaframework.SchemaManager.createForeignConstraints(SchemaManager.java:194)
它们似乎与为@OneToMany,@ ManyToMany等关联创建的外键约束有关。 现在还有一些JUnit测试没有通过与此类ManyToMany中关联的实体的批量删除(DELETE FROM)相关的测试。在hibernate中,这个测试传递得很好,在EclipseLink中有一些错误。
我不知道下面的错误外键约束是否会影响这种情况? 如果EclipseLink具有完全不同的实现,并且很难从Hibernate移植应用程序(在Hibernate中工作的代码在EclipseLink中不起作用)
现在我看到在Hibernate中也存在类似的错误:
HHH000389: Unsuccessful: alter table natural_person drop foreign key FK_xebs35hpmkrexufr4i267ak1
Table "NATURAL_PERSON" not found; SQL statement:
alter table natural_person
drop
foreign key FK_xebs35hpmkrexufr4i267ak1 [42102-173]
</event></ijLog>
ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] HHH000389: Unsuccessful: alter table natural_person drop foreign key FK_xebs35hpmkrexufr4i267ak1
ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] Table "NATURAL_PERSON" not found; SQL statement:
alter table natural_person
drop
foreign key FK_xebs35hpmkrexufr4i267ak1 [42102-173]
HHH000389: Unsuccessful: alter table photo_tagged_with drop foreign key FK_gcjvuf4mauiptth529s2e4gjw
HHH000389: Unsuccessful: alter table provider drop foreign key fk_provider_corporation
Table 'salonea.provider' doesn't exist
Table "PHOTO_TAGGED_WITH" not found; SQL statement:
alter table photo_tagged_with
drop
foreign key FK_gcjvuf4mauiptth529s2e4gjw [42102-173]