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

Entity with multiple embeddable records is broken in EclipseLink #2246

Open
Riva-Tholoor-Philip opened this issue Aug 22, 2024 · 0 comments
Open

Comments

@Riva-Tholoor-Philip
Copy link
Contributor

After the fix for #2214 went in, tests fail when trying to insert an entity that has multiple embeddable records. The database raises an error,

Column name 'X' appears more than once times in the column list of an INSERT statement

After EclipseLink tries to use the same column for both embeddable field.

Entity:

@Entity
public class Segment {

    @GeneratedValue
    @Id
    public Long id;

    @Embedded
    @Column(nullable = false)
    public Point pointA;

    @Embedded
    @Column(nullable = false)
    public Point pointB;
}

Embeddable class:

@Embeddable
public record Point(int x, int y) {
}

SQL that we see EclipseLink using:

CREATE TABLE WLPSegment (ID BIGINT NOT NULL, X INTEGER, Y INTEGER, PRIMARY KEY (ID))
INSERT INTO WLPSegment (ID, X, Y, X, Y) VALUES (?, ?, ?, ?, ?)

Full exception stack:

CWWKD0291W: Exception [EclipseLink-4002] (Eclipse Persistence Services - 5.0.0.v202408200932-f556522e743c87b8097f78cefe2b8f24f68cf79e): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Column name 'X' appears more than once times in the column list of an INSERT statement. 
Error Code: 20000
Call: INSERT INTO WLPSegment (ID, X, Y, X, Y) VALUES (?, ?, ?, ?, ?)
	bind => [5 parameters bound]
Query: InsertObjectQuery(Segment#46 (0, 0) -> (120, 209))
[8/21/24, 11:59:19:606 CDT] 00000064 id=00000000 eclipselink.ps                                               3 throwable 
                                                                                                               Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 5.0.0.v202408200932-f556522e743c87b8097f78cefe2b8f24f68cf79e): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Column name 'X' appears more than once times in the column list of an INSERT statement. 
Error Code: 20000
Call: INSERT INTO WLPSegment (ID, X, Y, X, Y) VALUES (?, ?, ?, ?, ?)
	bind => [5 parameters bound]
Query: InsertObjectQuery(Segment#46 (0, 0) -> (120, 209))
	at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:346)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:702)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:569)
	at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2053)
	at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:322)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:282)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:268)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:438)
	at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:194)
	at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:210)
	at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:514)
	at org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:86)
	at org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:97)
	at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:326)
	at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:63)
	at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:934)
	at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:833)
	at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:114)
	at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:91)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:3015)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1848)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1830)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1780)
	at org.eclipse.persistence.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:248)
	at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:147)
	at org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:4340)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1515)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithPreBuiltChangeSet(UnitOfWorkImpl.java:1651)
	at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.writeChanges(RepeatableWriteUnitOfWork.java:477)
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:997)
	Caused by: java.sql.SQLSyntaxErrorException: Column name 'X' appears more than once times in the column list of an INSERT statement. 
	at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
	at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedPreparedStatement42.<init>(Unknown Source)
	at org.apache.derby.jdbc.Driver42.newEmbedPreparedStatement(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
	at org.apache.derby.iapi.jdbc.BrokeredConnection.prepareStatement(Unknown Source)
	at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.prepareStatement(WSJdbcConnection.java:2237)
	at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.prepareStatement(WSJdbcConnection.java:2202)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1751)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1698)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseCall.prepareStatement(DatabaseCall.java:766)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:630)
	... 68 more
Caused by: ERROR 42X13: Column name 'X' appears more than once times in the column list of an INSERT statement. 
	at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
	at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
	at org.apache.derby.impl.sql.compile.ResultColumnList.bindResultColumnsByName(Unknown Source)
	at org.apache.derby.impl.sql.compile.InsertNode.bindStatement(Unknown Source)
	at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
	at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
	at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
	... 80 more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant