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

EclipseLink doesn't generate SQL UPDATE correctly if @ReturnUpdate is used in InheritanceType.JOINED #1016

Closed
rfelcman opened this issue Feb 12, 2021 · 0 comments
Assignees

Comments

@rfelcman
Copy link
Contributor

SQL UPDATE command is not correctly generated if @ReturnUpdate is used in InheritanceType.JOINED. It started from 2.7.7. It is related with fix for #709 .
Test case to simulate it:
DB Tables:

CREATE TABLE JPA22_RETURNINSERTUPDATE_MASTER_JOINED  (
    ID     NUMBER(15) PRIMARY KEY ,
    TYPE   VARCHAR2(50) NOT NULL
  );

CREATE TABLE JPA22_RETURNINSERTUPDATE_DETAIL_JOINED  (
    ID                  NUMBER(15) PRIMARY KEY ,
    DETAIL_NR           NUMBER(15),
    DETAIL_NR_VIRTUAL   NUMBER(15) AS ( DETAIL_NR * 10 ) VIRTUAL
);

There are two entities:

...
@Entity
@Table(name = "JPA22_RETURNINSERTUPDATE_MASTER_JOINED")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
@SequenceGenerator(name = "AbstractEntityObjectSEQ_STORE", sequenceName = "TEST_RETURNINSERT_MASTER_JOINED_ID_SEQ", allocationSize = 1)
public class ReturnInsertUpdateMasterJoined implements Serializable {
...
...
@Entity
@Table(name = "JPA22_RETURNINSERTUPDATE_DETAIL_JOINED")
@PrimaryKeyJoinColumn(name = "id")
@DiscriminatorValue("A")
public class ReturnInsertUpdateDetailJoined extends ReturnInsertUpdateMasterJoined {
...

Fields in ReturnInsertUpdateDetailJoined

@Column(name = "detail_nr")
Long detailNumber = null;

@Column(name = "detail_nr_virtual", nullable = false, unique = true, updatable = false)
@ReturnInsert(returnOnly = true)
@ReturnUpdate
Long detailNumberVirtual = null;

There are two possible errors:

  1. For field update in JPA22_RETURNINSERTUPDATE_DETAIL_JOINED table only
...
ReturnInsertUpdateDetailJoined returnInsertUpdateDetail  = em.find(ReturnInsertUpdateDetailJoined.class, 1L);
returnInsertUpdateDetail.setDetailNumber(22L);
returnInsertUpdateDetailJoined = em.merge(returnInsertUpdateDetail);
em.getTransaction().commit();
...

NPE is thrown

[EL Warning]: 2021-02-12 13:13:59.819--UnitOfWork(923013679)--Thread(Thread[main,5,main])--java.lang.NullPointerException
	at org.eclipse.persistence.platform.database.OraclePlatform.buildCallWithReturning(OraclePlatform.java:275)
	at org.eclipse.persistence.internal.expressions.SQLModifyStatement.buildCall(SQLModifyStatement.java:67)
	at org.eclipse.persistence.descriptors.ClassDescriptor.buildCallFromStatement(ClassDescriptor.java:885)
	at org.eclipse.persistence.internal.queries.StatementQueryMechanism.setCallFromStatement(StatementQueryMechanism.java:379)
...
  1. Update fields in JPA22_RETURNINSERTUPDATE_MASTER_JOINED, JPA22_RETURNINSERTUPDATE_DETAIL_JOINED tables
...
ReturnInsertUpdateDetailJoined returnInsertUpdateDetail  = em.find(ReturnInsertUpdateDetailJoined.class, 1L);
returnInsertDetail.setType("TYPE_B");
returnInsertUpdateDetail.setDetailNumber(22L);
returnInsertUpdateDetailJoined = em.merge(returnInsertUpdateDetail);
em.getTransaction().commit();
...

leads into

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.8.v20201217-ecdf3c32c4): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-06550: line 1, column 99:
PL/SQL: ORA-00904: "DETAIL_NR_VIRTUAL": invalid identifier
ORA-06550: line 1, column 7:
PL/SQL: SQL Statement ignored

Error Code: 6550
Call: BEGIN UPDATE JPA22_RETURNINSERTUPDATE_MASTER_JOINED SET type = ? WHERE (ID = ?) RETURNING detail_nr_virtual INTO ?; END;
	bind => [TYPE_B, 1, => detail_nr_virtual]
Query: UpdateObjectQuery(org.eclipse.persistence.jpa.returninsert.model.ReturnInsertUpdateDetailJoined@3e58d65e)
	at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:908)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:970)
...
@rfelcman rfelcman self-assigned this Feb 12, 2021
rfelcman added a commit that referenced this issue Feb 16, 2021
… used in InheritanceType.JOINED (#1017)

EclipseLink doesn't generate SQL UPDATE correctly if @ReturnUpdate is used in InheritanceType.JOINED
bugfix for #1016  + unit test

Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
rfelcman added a commit that referenced this issue Feb 16, 2021
… used in InheritanceType.JOINED (#1018)

bugfix for #1016 + unit test

Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
rfelcman added a commit that referenced this issue Nov 25, 2021
…nit test (#1364)

Standalone usage ReturnUpdate annotation was broken in PR #1016.
fixes #1363

Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
rfelcman added a commit to rfelcman/eclipselink that referenced this issue Nov 25, 2021
…nit test (eclipse-ee4j#1364)

Standalone usage ReturnUpdate annotation was broken in PR eclipse-ee4j#1016.
fixes eclipse-ee4j#1363

Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
(cherry picked from commit fb1cc69)
rfelcman added a commit that referenced this issue Nov 29, 2021
…nit test (#1364) (#1365)

Standalone usage ReturnUpdate annotation was broken in PR #1016.
fixes #1363

Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
(cherry picked from commit fb1cc69)
rfelcman added a commit that referenced this issue Nov 29, 2021
…nit test (#1366)

Standalone usage ReturnUpdate annotation was broken in PR #1016.
fixes #1363

Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
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