eclipselink icon indicating copy to clipboard operation
eclipselink copied to clipboard

Fix malformed sql

Open kalinchan opened this issue 1 year ago • 2 comments

Credit to @luiseufrasio Malformed SQL when using SecondaryTable & PrimaryKeyJoinColumn annotations

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.8.payara-p3): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703, SQLERRMC=T0.HCSO#, DRIVER=4.32.28 Error Code: -206 Call: SELECT t0.HDSO#, t1.HCSO#, t0.HDCUST, t0.HDYEAR, t0.HDRLSO, t1.HCUSER FROM SOHDS0 t0, SOHC t1 WHERE ((t0.HDSO# = ?) AND (t0.HCSO# = t0.HDSO#)) bind => [123] Query: ReadObjectQuery(name="readSalesOrder" referenceClass=FleetSalesOrder sql="SELECT t0.HDSO#, t1.HCSO#, t0.HDCUST, t0.HDYEAR, t0.HDRLSO, t1.HCUSER FROM SOHDS0 t0, SOHC t1 WHERE ((t0.HDSO# = ?) AND (t0.HCSO# = t0.HDSO#))")

The AND clause at the very end should have condition t1.HCSO# = t0.HDSO#

kalinchan avatar Sep 23 '24 11:09 kalinchan

Hi, looking at Employee.java it doesn't seem to be the same use case.

In this situation, the following annotation is causing the error:

@SecondaryTable(name = "SOHC",//, schema = "OEF",
        pkJoinColumns = @PrimaryKeyJoinColumn(name = "HCSO#", referencedColumnName = "HDSO#"))

Is there a different place to write the test or is the Employee class still valid?

kalinchan avatar Oct 04 '24 10:10 kalinchan

Maybe something based on https://github.com/eclipse-ee4j/eclipselink/blob/master/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/sequence/model/Tea.java https://github.com/eclipse-ee4j/eclipselink/blob/master/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/sequence/TestIdentityGeneration.java#L88 add there some operation (like JPQL SELECT - em.createQuery(...).getSingleResult()) which leads into mentioned issue.

rfelcman avatar Oct 04 '24 12:10 rfelcman