Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDL generation grabs column info for the wrong table #1612

Closed
lukasj opened this issue Aug 2, 2022 · 0 comments · Fixed by #1615
Closed

DDL generation grabs column info for the wrong table #1612

lukasj opened this issue Aug 2, 2022 · 0 comments · Fixed by #1615
Labels
bug Something isn't working

Comments

@lukasj
Copy link
Member

lukasj commented Aug 2, 2022

Noticed this in the DDLGenerationExtendTablesTestSuite running sequentially against two different schemas on mysql.

assuming there are two empty DB schemas t1 and t2 on mysql and the test is to end up with a table Countries, with columns iso_code and name where the name column is added by the create-or-extend-tables DDL option

First run on t1 always passes - the particular table gets created with one column, later extended with the new, name, column by the test and all following tests are passing.

Second run on t2 fails with:

Error persisting new country with city, states and zips : jakarta.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 4.0.0.v202208012021): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Unknown column 'name' in 'field list'
Error Code: 1054
Call: INSERT INTO Countries (iso_code, name) VALUES (?, ?)
	bind => [840, USA]
Query: InsertObjectQuery(org.eclipse.persistence.testing.models.jpa.ddlgeneration.Country@705fe9f2)
	at deployment.org.eclipse.persistence.jpa.testapps.ddlgeneration.ear//junit.framework.Assert.fail(Assert.java:57)
	at deployment.org.eclipse.persistence.jpa.testapps.ddlgeneration.ear//junit.framework.TestCase.fail(TestCase.java:223)
	at deployment.org.eclipse.persistence.jpa.testapps.ddlgeneration.ear.org.eclipse.persistence.jpa.testapps.ddlgeneration_ejb.jar//org.eclipse.persistence.testing.tests.jpa.ddlgeneration.DDLGenerationTest.testPrimaryKeyJoinColumns(DDLGenerationTest.java:276)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...

the problem is, that the table in the t2 schema is not extended with the name column.

The cause is that the schemaframework (the part responsible for DDL) does not take into account current schema and catalog when querying the DB for the column names of the particular table, so when it asks for columns of the Countries table, what gets returned is actually info about the Countries table from schema t1 where all columns are already present instead of the same table from schema t2 where the to be created name column is missing, so in the end, the query checking the state of the Countries table in schema t2 fails.

@lukasj lukasj changed the title DDL generation grabs column info from the wrong table DDL generation grabs column info for the wrong table Aug 2, 2022
@lukasj lukasj added the bug Something isn't working label Aug 2, 2022
lukasj added a commit to lukasj/eclipselink that referenced this issue Aug 2, 2022
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
lukasj added a commit that referenced this issue Aug 2, 2022
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant