problems with session customizer when upgrading to 2.7.9 - bugfix + unit test (#1364)

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

Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/queries/ExpressionQueryMechanism.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/queries/ExpressionQueryMechanism.java
index 863a7d7..00ae635 100644
--- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/queries/ExpressionQueryMechanism.java
+++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/queries/ExpressionQueryMechanism.java
@@ -837,12 +837,12 @@
         if (getDescriptor().hasReturningPolicies() && getDescriptor().getReturnFieldsToGenerateUpdate() != null) {
             // In case of RelationalDescriptor only return fields for current table must be used.
             List<DatabaseField> returnFieldsForTable = new ArrayList<>();
-            for (DatabaseField item: getDescriptor().getReturnFieldsToGenerateInsert()) {
+            for (DatabaseField item: getDescriptor().getReturnFieldsToGenerateUpdate()) {
                 if (table.equals(item.getTable())) {
                     returnFieldsForTable.add(item);
                 }
                 if (!returnFieldsForTable.isEmpty()) {
-                    updateStatement.setReturnFields(getDescriptor().getReturnFieldsToGenerateInsert());
+                    updateStatement.setReturnFields(getDescriptor().getReturnFieldsToGenerateUpdate());
                 }
             }
         }
diff --git a/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/returninsert/TestReturnInsert.java b/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/returninsert/TestReturnInsert.java
index e20acc0..25faa69 100644
--- a/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/returninsert/TestReturnInsert.java
+++ b/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/returninsert/TestReturnInsert.java
@@ -30,6 +30,7 @@
 
 import static junit.framework.TestCase.assertEquals;
 import static junit.framework.TestCase.assertNotNull;
+import static org.junit.Assert.fail;
 
 /**
  * TestSuite to test entities, that has a @ReturnInsert and @ReturnUpdate annotations.
@@ -106,7 +107,9 @@
                         "    COL4     VARCHAR (15) NOT NULL," +
                         "    COL4_VIRTUAL VARCHAR (100) AS ( COL4 || '_col4' ) VIRTUAL," +
                         "    COL5     VARCHAR (15) NOT NULL," +
-                        "    COL5_VIRTUAL VARCHAR (100) AS ( COL5 || '_col5' ) VIRTUAL)");
+                        "    COL5_VIRTUAL VARCHAR (100) AS ( COL5 || '_col5' ) VIRTUAL," +
+                        "    COL6     VARCHAR (15) NOT NULL," +
+                        "    COL6_VIRTUAL VARCHAR (100) AS ( COL6 || '_col6' ) VIRTUAL)");
                 session.executeNonSelectingSQL("ALTER TABLE JPA22_RETURNINSERT_DETAIL ADD CONSTRAINT PKJPA22_RETURNINSERT_DETAIL PRIMARY KEY ( ID_VIRTUAL, ID, COL1, COL2 )");
                 session.executeNonSelectingSQL("ALTER TABLE JPA22_RETURNINSERT_DETAIL ADD CONSTRAINT FKJPA22_RETURNINSERT_MASTER_DETAIL FOREIGN KEY ( ID_VIRTUAL, ID, COL1 ) REFERENCES JPA22_RETURNINSERT_MASTER ( ID_VIRTUAL, ID, COL1 ) NOT DEFERRABLE");
                 session.executeNonSelectingSQL("CREATE TABLE JPA22_RETURNINSERT_MASTER_JOINED  (" +
@@ -142,6 +145,8 @@
             returnInsertDetail = insertReturnInsertDetail(em, returnInsertMaster);
 
         em.getTransaction().commit();
+        } catch (Exception e) {
+            fail(e.getMessage());
         } finally {
             if (em.getTransaction().isActive()) {
                 em.getTransaction().rollback();
@@ -170,6 +175,8 @@
             returnInsertDetailJoined = em.merge(returnInsertDetailJoined);
 
             em.getTransaction().commit();
+        } catch (Exception e) {
+            fail(e.getMessage());
         } finally {
             if (em.getTransaction().isActive()) {
                 em.getTransaction().rollback();
@@ -195,6 +202,8 @@
             returnInsertDetailJoined = em.merge(returnInsertDetailJoined);
 
             em.getTransaction().commit();
+        } catch (Exception e) {
+            fail(e.getMessage());
         } finally {
             if (em.getTransaction().isActive()) {
                 em.getTransaction().rollback();
@@ -219,6 +228,8 @@
             returnInsertDetailJoined = em.merge(returnInsertDetailJoined);
 
             em.getTransaction().commit();
+        } catch (Exception e) {
+            fail(e.getMessage());
         } finally {
             if (em.getTransaction().isActive()) {
                 em.getTransaction().rollback();
@@ -251,9 +262,12 @@
             assertEquals("abc_col2", returnInsertDetailFindResult.getReturnInsertDetailEmbedded().getCol2Virtual());
             //Test update
             returnInsertDetailFindResult.getReturnInsertDetailEmbedded().setCol3("ijk");
+            returnInsertDetailFindResult.setCol6("rst");
             returnInsertDetailMerge = em.merge(returnInsertDetailFindResult);
 
             em.getTransaction().commit();
+        } catch (Exception e) {
+            fail(e.getMessage());
         } finally {
             if (em.getTransaction().isActive()) {
                 em.getTransaction().rollback();
@@ -263,6 +277,7 @@
             }
         }
         assertEquals("ijk_col3", returnInsertDetailMerge.getReturnInsertDetailEmbedded().getCol3Virtual());
+        assertEquals("rst_col6", returnInsertDetailMerge.getCol6Virtual());
     }
 
     private void testQuery() {
@@ -277,6 +292,8 @@
             Query query  = em.createQuery("select t from ReturnInsertDetail t where t.id = :returnInsertDetailId");
             query.setParameter("returnInsertDetailId", returnInsertDetailPK);
             returnInsertDetailQueryResult = (ReturnInsertDetail) query.getSingleResult();
+        } catch (Exception e) {
+            fail(e.getMessage());
         } finally {
             if (em.getTransaction().isActive()) {
                 em.getTransaction().rollback();
@@ -310,7 +327,9 @@
             DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
             Date date = dateFormat.parse("1970-01-01 00:00:00.0");
             ReturnInsertMasterPK.setId(date);
-        } catch (Exception e) { }
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
         ReturnInsertMasterPK.setCol1(1L);
         return ReturnInsertMasterPK;
     }
@@ -337,6 +356,8 @@
         //Inherited field
         returnInsertDetail.setCol4("opq");
 
+        returnInsertDetail.setCol6("rst");
+
         em.persist(returnInsertDetail);
         return returnInsertDetail;
     }
@@ -348,7 +369,9 @@
             DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
             Date date = dateFormat.parse("1970-01-01 00:00:00.0");
             returnInsertDetailPK.setId(date);
-        } catch (Exception e) { }
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
         returnInsertDetailPK.setCol1(1L);
         returnInsertDetailPK.setCol2("abc");
         return returnInsertDetailPK;
diff --git a/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/returninsert/model/ReturnInsertDetail.java b/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/returninsert/model/ReturnInsertDetail.java
index edb1f56..c456c87 100644
--- a/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/returninsert/model/ReturnInsertDetail.java
+++ b/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/returninsert/model/ReturnInsertDetail.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v. 2.0 which is available at
@@ -17,6 +17,8 @@
 import org.eclipse.persistence.annotations.ReturnInsert;
 
 import jakarta.persistence.*;
+import org.eclipse.persistence.annotations.ReturnUpdate;
+
 import java.io.Serializable;
 
 /**
@@ -43,6 +45,13 @@
 	@Embedded
 	private ReturnInsertDetailEmbedded returnInsertDetailEmbedded;
 
+	@Column(name = "COL6")
+	private String col6;
+
+	@ReturnUpdate
+	@Column(name = "COL6_VIRTUAL", insertable = false)
+	private String col6Virtual;
+
 	@OneToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST })
 	@JoinColumns({
 			@JoinColumn(name = "ID_VIRTUAL", referencedColumnName = "ID_VIRTUAL", insertable = false, updatable = false),
@@ -78,6 +87,22 @@
 		this.returnInsertDetailEmbedded = returnInsertDetailEmbedded;
 	}
 
+	public String getCol6() {
+		return col6;
+	}
+
+	public void setCol6(String col6) {
+		this.col6 = col6;
+	}
+
+	public String getCol6Virtual() {
+		return col6Virtual;
+	}
+
+	public void setCol6Virtual(String col6Virtual) {
+		this.col6Virtual = col6Virtual;
+	}
+
 	public ReturnInsertMaster getReturnInsertMaster() {
 		return returnInsertMaster;
 	}