Merge pull request #458 from johnthuss/nestedTwoStageCommitFailure

Add failing test for using a nested context with a two-stage commit
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index b14933a..52f65a9 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -13,6 +13,8 @@
 ----------------------------------
 Changes/New Features:
 
+CAY-2399 Convert string values to Enum in qualifiers
+
 Bug Fixes:
 
 CAY-2092 Exception for query that uses pagination and sorting on to-many
@@ -24,6 +26,7 @@
 CAY-2708 Gradle build plugin fails on Java 16
 CAY-2709 Modeler: Cgen fails to generate code for a new unsaved project with all settings set to default
 CAY-2710 Modeler: modeler throws IllegalArgumentsException when root and rel paths have different root
+CAY-2712 Shouldn't run batch inserts with generated keys if there is reflexive dependency
 
 ----------------------------------
 Release: 4.2.M3
diff --git a/assembly/pom.xml b/assembly/pom.xml
index 8f2effd..1d79f1c 100644
--- a/assembly/pom.xml
+++ b/assembly/pom.xml
@@ -196,6 +196,22 @@
 			<build>
 				<plugins>
 					<plugin>
+						<artifactId>maven-remote-resources-plugin</artifactId>
+						<executions>
+							<execution>
+								<goals>
+									<goal>process</goal>
+								</goals>
+								<configuration>
+									<outputDirectory>${project.build.directory}/legal</outputDirectory>
+									<properties>
+										<binary>false</binary>
+									</properties>
+								</configuration>
+							</execution>
+						</executions>
+					</plugin>
+					<plugin>
 						<artifactId>maven-assembly-plugin</artifactId>
 						<executions>
 							<execution>
@@ -222,19 +238,6 @@
 			<build>
 				<plugins>
 					<plugin>
-						<artifactId>maven-remote-resources-plugin</artifactId>
-						<executions>
-							<execution>
-								<goals>
-									<goal>process</goal>
-								</goals>
-								<configuration>
-									<outputDirectory>${project.build.directory}/legal</outputDirectory>
-								</configuration>
-							</execution>
-						</executions>
-	                </plugin>
-					<plugin>
 						<groupId>org.apache.maven.plugins</groupId>
 						<artifactId>maven-assembly-plugin</artifactId>
 						<configuration>
@@ -281,6 +284,22 @@
 			<build>
 				<plugins>
 					<plugin>
+						<artifactId>maven-remote-resources-plugin</artifactId>
+						<executions>
+							<execution>
+								<goals>
+									<goal>process</goal>
+								</goals>
+								<configuration>
+									<outputDirectory>${project.build.directory}/legal</outputDirectory>
+									<properties>
+										<binary>true</binary>
+									</properties>
+								</configuration>
+							</execution>
+						</executions>
+					</plugin>
+					<plugin>
 						<artifactId>maven-assembly-plugin</artifactId>
 						<executions>
 							<execution>
@@ -338,6 +357,22 @@
 						</executions>
 					</plugin>
 					<plugin>
+						<artifactId>maven-remote-resources-plugin</artifactId>
+						<executions>
+							<execution>
+								<goals>
+									<goal>process</goal>
+								</goals>
+								<configuration>
+									<outputDirectory>${project.build.directory}/legal</outputDirectory>
+									<properties>
+										<binary>true</binary>
+									</properties>
+								</configuration>
+							</execution>
+						</executions>
+					</plugin>
+					<plugin>
 						<artifactId>maven-assembly-plugin</artifactId>
 						<executions>
 							<execution>
@@ -431,6 +466,22 @@
 						</executions>
 					</plugin>
 					<plugin>
+						<artifactId>maven-remote-resources-plugin</artifactId>
+						<executions>
+							<execution>
+								<goals>
+									<goal>process</goal>
+								</goals>
+								<configuration>
+									<outputDirectory>${project.build.directory}/legal</outputDirectory>
+									<properties>
+										<binary>true</binary>
+									</properties>
+								</configuration>
+							</execution>
+						</executions>
+					</plugin>
+					<plugin>
 						<artifactId>maven-assembly-plugin</artifactId>
 						<executions>
 							<execution>
diff --git a/assembly/src/main/resources/assemblies/src/assembly-src.xml b/assembly/src/main/resources/assemblies/src/assembly-src.xml
index 3eb5ed2..ca2b8ab 100644
--- a/assembly/src/main/resources/assemblies/src/assembly-src.xml
+++ b/assembly/src/main/resources/assemblies/src/assembly-src.xml
@@ -37,6 +37,9 @@
                 <exclude>**/.project</exclude>
                 <exclude>**/.settings</exclude>
 				<exclude>**/out/**</exclude>
+				<exclude>**/build/**</exclude>
+				<exclude>**/gradle/**</exclude>
+				<exclude>**/.gradle/**</exclude>
 			</excludes>
 		</fileSet>
 		<fileSet>
diff --git a/build-tools/cayenne-legal/src/main/resources/META-INF/cayenne/LICENSE.txt b/build-tools/cayenne-legal/src/main/resources/META-INF/cayenne/LICENSE.txt.vm
similarity index 76%
rename from build-tools/cayenne-legal/src/main/resources/META-INF/cayenne/LICENSE.txt
rename to build-tools/cayenne-legal/src/main/resources/META-INF/cayenne/LICENSE.txt.vm
index 4aec7e2..4007b13 100644
--- a/build-tools/cayenne-legal/src/main/resources/META-INF/cayenne/LICENSE.txt
+++ b/build-tools/cayenne-legal/src/main/resources/META-INF/cayenne/LICENSE.txt.vm
@@ -263,6 +263,68 @@
 <http://objectstyle.org/>.
 
 =====================================================================
+3. ASHWOOD LICENSE	
+
+ *
+ * Copyright(c) 2003, Andriy Shapochka
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the ASHWOOD nor the
+ *    names of its contributors may be used to endorse or
+ *    promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by
+ * individuals on behalf of the ASHWOOD Project and was originally
+ * created by Andriy Shapochka.
+ */
+=====================================================================
+
+concurrentlinkedhashmap License
+
+
+Copyright 2010 Google Inc. All Rights Reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     https://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+#if($binary == "true")
+=====================================================================
 CAUCHO LICENSE
 
  Copyright (c) 2001-2004 Caucho Technology, Inc.  All rights reserved.
@@ -308,49 +370,7 @@
  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- 
-=====================================================================
-3. ASHWOOD LICENSE	
 
- *
- * Copyright(c) 2003, Andriy Shapochka
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above
- *    copyright notice, this list of conditions and the following
- *    disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above
- *    copyright notice, this list of conditions and the following
- *    disclaimer in the documentation and/or other materials
- *    provided with the distribution.
- *
- * 3. Neither the name of the ASHWOOD nor the
- *    names of its contributors may be used to endorse or
- *    promote products derived from this software without
- *    specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * ====================================================================
- *
- * This software consists of voluntary contributions made by
- * individuals on behalf of the ASHWOOD Project and was originally
- * created by Andriy Shapochka.
- */
 =====================================================================
 JGOODIES LICENSE
 
@@ -359,30 +379,30 @@
 
 Copyright (c) 2003 JGoodies Karsten Lentzsch. All rights reserved.
 
-Redistribution and use in source and binary forms, with or without 
+Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 
- o Redistributions of source code must retain the above copyright notice, 
-   this list of conditions and the following disclaimer. 
-    
- o Redistributions in binary form must reproduce the above copyright notice, 
-   this list of conditions and the following disclaimer in the documentation 
-   and/or other materials provided with the distribution. 
-    
- o Neither the name of JGoodies Karsten Lentzsch nor the names of 
-   its contributors may be used to endorse or promote products derived 
-   from this software without specific prior written permission. 
-    
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
-PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
-CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
-EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
-OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
-OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
+ o Redistributions of source code must retain the above copyright notice,
+   this list of conditions and the following disclaimer.
+
+ o Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution.
+
+ o Neither the name of JGoodies Karsten Lentzsch nor the names of
+   its contributors may be used to endorse or promote products derived
+   from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 =====================================================================
@@ -418,86 +438,6 @@
 //  DAMAGE.
 
 =====================================================================
-Eclipse Public License -v 1.0
-
-(plain text)
-
-THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
-
-1. DEFINITIONS
-
-"Contribution" means:
-
-    a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
-    b) in the case of each subsequent Contributor:
-    i) changes to the Program, and
-    ii) additions to the Program; 
-
-where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
-
-"Contributor" means any person or entity that distributes the Program.
-
-"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
-
-"Program" means the Contributions distributed in accordance with this Agreement.
-
-"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
-
-2. GRANT OF RIGHTS
-
-    a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
-    b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
-    c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
-    d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
-
-    3. REQUIREMENTS
-
-    A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
-
-        a) it complies with the terms and conditions of this Agreement; and
-        b) its license agreement:
-        i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
-        ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
-        iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
-        iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. 
-
-    When the Program is made available in source code form:
-
-        a) it must be made available under this Agreement; and
-        b) a copy of this Agreement must be included with each copy of the Program. 
-
-    Contributors may not remove or alter any copyright notices contained within the Program.
-
-    Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
-
-    4. COMMERCIAL DISTRIBUTION
-
-    Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
-
-    For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
-
-    5. NO WARRANTY
-
-    EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
-
-    6. DISCLAIMER OF LIABILITY
-
-    EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-
-    7. GENERAL
-
-    If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
-
-    If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
-
-    All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
-
-    Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
-
-    This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
-
-
-=====================================================================
 VPP License
 
 Copyright (c) 2003, FoundryLogic, LLC
@@ -797,25 +737,6 @@
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 =====================================================================
-concurrentlinkedhashmap License
-
-
-Copyright 2010 Google Inc. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
-     https://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-
-=====================================================================
 SLF4J License
 
  Copyright (c) 2004-2017 QOS.ch
@@ -838,4 +759,5 @@
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT OF OR IN CONNECTION
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#end
\ No newline at end of file
diff --git a/build-tools/cayenne-legal/src/main/resources/META-INF/cayenne/NOTICE.txt b/build-tools/cayenne-legal/src/main/resources/META-INF/cayenne/NOTICE.txt.vm
similarity index 92%
rename from build-tools/cayenne-legal/src/main/resources/META-INF/cayenne/NOTICE.txt
rename to build-tools/cayenne-legal/src/main/resources/META-INF/cayenne/NOTICE.txt.vm
index 57b833a..af6a8a8 100644
--- a/build-tools/cayenne-legal/src/main/resources/META-INF/cayenne/NOTICE.txt
+++ b/build-tools/cayenne-legal/src/main/resources/META-INF/cayenne/NOTICE.txt.vm
@@ -4,23 +4,26 @@
 This product includes software developed at
 The Apache Software Foundation (http://www.apache.org/).
 
-
+#if($binary == "true")
 RUNTIME FRAMEWORK
 
+#end
 * ObjectStyle Cayenne Notice: This software is derived from Cayenne Framework, 
 originally developed at The ObjectStyle Group and donated to the ASF by its authors
 (http://objectstyle.org)
 
 * This software includes Ashwood graph library developed by Andriy Shapochka.
 (http://objectstyle.org/ashwood/)
+#if($binary == "true")
 
 * This software includes VPP library developed by FoundryLogic, LLC.
 (http://vpp.sourceforge.net/)
+#end
 
 * This software includes concurrentlinkedhashmap library developed by Google Inc.
 (http://code.google.com/p/concurrentlinkedhashmap/)
 
-
+#if($binary == "true")
 GUI TOOLS
 
 * CayenneModeler includes JGoodies library developed by Karsten Lentzsch.
@@ -29,9 +32,6 @@
 * CayenneModeler includes OGNL library developed by Drew Davidson and Luke Blanshard
 (http://commons.apache.org/ognl/)
 
-* CayenneModeler includes GIF binary images developed by Eclipse Foundation. 
-(http://www.eclipse.org/).
-
 * CayenneModeler includes jEdit-syntax library developed by Slava Pestov, Artur Biesiadowski, 
 Clancy Malcolm, Jonathan Revusky, Juha Lindfors and Mike Dillon.
 (http://jedit-syntax.sourceforge.net/)
@@ -41,4 +41,4 @@
 
 * CayenneModeler includes JGraph library developed by JGraph Ltd
 (http://www.jgraph.com)
-
+#end
\ No newline at end of file
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbAttributeMerger.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbAttributeMerger.java
index 8e0500f..81c7f33 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbAttributeMerger.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbAttributeMerger.java
@@ -34,6 +34,13 @@
 
 class DbAttributeMerger extends AbstractMerger<DbEntity, DbAttribute> {
 
+    static int[] typesWithMaxLength = {
+            Types.NCHAR, Types.NVARCHAR,
+            Types.CHAR, Types.VARCHAR,
+            Types.BINARY, Types.VARBINARY,
+            Types.TIME, Types.TIMESTAMP
+    };
+
     private final ValueForNullProvider valueForNull;
 
     DbAttributeMerger(MergerTokenFactory tokenFactory, ValueForNullProvider valueForNull) {
@@ -137,11 +144,6 @@
         }
 
         if(original.getMaxLength() != imported.getMaxLength()) {
-            int[] typesWithMaxLength = {
-                    Types.NCHAR, Types.NVARCHAR,
-                    Types.CHAR, Types.VARCHAR,
-                    Types.BINARY, Types.VARBINARY
-            };
             for(int type : typesWithMaxLength) {
                 if(original.getType() == type) {
                     return true;
diff --git a/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/merge/CheckTypeTest.java b/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/merge/CheckTypeTest.java
index 87a3cfc..387d2ab 100644
--- a/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/merge/CheckTypeTest.java
+++ b/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/merge/CheckTypeTest.java
@@ -169,6 +169,22 @@
     }
 
     @Test
+    public void testTimeType() {
+        original.setType(Types.TIMESTAMP);
+        original.setMaxLength(19);
+
+        imported.setType(Types.TIMESTAMP);
+        imported.setMaxLength(0);
+
+        Collection<MergerToken> mergerTokens = dbAttributeMerger.createTokensForSame(diffPair);
+        assertEquals(1, mergerTokens.size());
+
+        MergerToken mergerToken1 = (MergerToken) mergerTokens.toArray()[0];
+        String mergerToken = "NEW_TABLE.NAME maxLength: 0 -> 19";
+        assertEquals(mergerToken, mergerToken1.getTokenValue());
+    }
+
+    @Test
     public void testCheckTypeWithoutChanges() {
 
         diffPair = new MergerDiffPair<>(original, imported);
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java b/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
index 6f798e3..4b0dc90 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
@@ -55,7 +55,7 @@
 	protected RowDescriptor keyRowDescriptor;
 
 	private static void bind(DbAdapter adapter, PreparedStatement statement, DbAttributeBinding[] bindings)
-			throws SQLException, Exception {
+			throws Exception {
 
 		for (DbAttributeBinding b : bindings) {
 			if (!b.isExcluded()) {
@@ -81,28 +81,39 @@
 	}
 
 	@Override
-	public void performAction(Connection connection, OperationObserver observer) throws SQLException, Exception {
-
+	public void performAction(Connection connection, OperationObserver observer) throws Exception {
 		BatchTranslator translator = createTranslator();
-		
-		boolean isBatch = runningAsBatch && query.getRows().size() > 1;
-		if (isBatch && hasGeneratedKeys() && !supportsGeneratedKeys(isBatch)) {
-			isBatch = false; // turn off batch mode if we generate keys but can't do so in a batch
-		}
-		
+
+		boolean isBatch = canRunAsBatch();
+		boolean generatesKeys = hasGeneratedKeys() && supportsGeneratedKeys(isBatch);
+
 		if (isBatch) {
-			runAsBatch(connection, translator, observer, hasGeneratedKeys() && supportsGeneratedKeys(isBatch));
+			runAsBatch(connection, translator, observer, generatesKeys);
 		} else {
-			runAsIndividualQueries(connection, translator, observer, hasGeneratedKeys() && supportsGeneratedKeys(isBatch));
+			runAsIndividualQueries(connection, translator, observer, generatesKeys);
 		}
 	}
 
+	protected boolean canRunAsBatch() {
+		if(!runningAsBatch || query.getRows().size() <= 1) {
+			return false;
+		}
+
+		if (hasGeneratedKeys()) {
+			// turn off batch mode if we generate keys but can't do so in a batch
+			return supportsGeneratedKeys(true) &&
+					!dataNode.getEntityResolver().getEntitySorter().isReflexive(query.getDbEntity());
+		}
+
+		return true;
+	}
+
 	protected BatchTranslator createTranslator() {
 		return dataNode.batchTranslator(query, null);
 	}
 
 	protected void runAsBatch(Connection con, BatchTranslator translator, OperationObserver delegate, boolean generatesKeys)
-			throws SQLException, Exception {
+			throws Exception {
 
 		String sql = translator.getSql();
 		JdbcEventLogger logger = dataNode.getJdbcEventLogger();
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/ashwood/AshwoodEntitySorter.java b/cayenne-server/src/main/java/org/apache/cayenne/ashwood/AshwoodEntitySorter.java
index 97c85e1..169ad91 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/ashwood/AshwoodEntitySorter.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/ashwood/AshwoodEntitySorter.java
@@ -170,6 +170,7 @@
 	@Override
 	public void setEntityResolver(EntityResolver entityResolver) {
 		this.entityResolver = entityResolver;
+		this.entityResolver.setEntitySorter(this);
 		this.dirty = true;
 	}
 
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTObjPath.java b/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTObjPath.java
index 4bd29dd..b118a91 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTObjPath.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTObjPath.java
@@ -24,10 +24,14 @@
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.DataObject;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.Entity;
+import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.reflect.PropertyUtils;
+import org.apache.cayenne.util.CayenneMapEntry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -99,7 +103,8 @@
 		if (!getPath().contains(ObjEntity.PATH_SEPARATOR)) {
 			try {
 				if (source instanceof DataObject) {
-					((DataObject) source).writeProperty(getPath(), value);
+					DataObject dataObject = (DataObject) source;
+					dataObject.writeProperty(getPath(), dynamicCastValue(dataObject, value));
 				} else {
 					PropertyUtils.setProperty(source, getPath(), value);
 				}
@@ -108,4 +113,35 @@
 			}
 		}
 	}
+
+	private Object dynamicCastValue(DataObject source, Object value) {
+		Class<?> javaClass = getDataTypeForObject(source);
+		if(javaClass == null) {
+			return value;
+		}
+
+		if(javaClass.isEnum()) {
+			@SuppressWarnings({"unchecked", "rawtypes"})
+			Enum enumValue = Enum.valueOf((Class<Enum>) javaClass, value.toString());
+			return enumValue;
+		}
+
+		return value;
+	}
+
+	private Class<?> getDataTypeForObject(DataObject source) {
+		ObjectContext context = source.getObjectContext();
+		ObjectId objectId = source.getObjectId();
+		if(context == null || objectId == null) {
+			return null;
+		}
+
+		ObjEntity entity = context.getEntityResolver().getObjEntity(objectId.getEntityName());
+		CayenneMapEntry entry = evaluateEntityNode(entity);
+		if(!(entry instanceof ObjAttribute)) {
+			return null;
+		}
+
+		return ((ObjAttribute) entry).getJavaClass();
+	}
 }
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java b/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java
index b62bfa3..ad0fd28 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java
@@ -100,6 +100,11 @@
      */
     protected transient ValueComparisonStrategyFactory valueComparisonStrategyFactory;
 
+    /**
+     * @since 4.2
+     */
+    protected transient EntitySorter entitySorter;
+
 
     /**
      * Creates new empty EntityResolver.
@@ -604,4 +609,17 @@
         this.valueComparisonStrategyFactory = valueComparisonStrategyFactory;
     }
 
+    /**
+     * @since 4.2
+     */
+    public void setEntitySorter(EntitySorter entitySorter) {
+        this.entitySorter = entitySorter;
+    }
+
+    /**
+     * @since 4.2
+     */
+    public EntitySorter getEntitySorter() {
+        return entitySorter;
+    }
 }
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/tx/BaseTransaction.java b/cayenne-server/src/main/java/org/apache/cayenne/tx/BaseTransaction.java
index a83990b..989dc88 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/tx/BaseTransaction.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/tx/BaseTransaction.java
@@ -204,7 +204,11 @@
         Connection c = getExistingConnection(connectionName);
 
         if (c == null || c.isClosed()) {
-            c = dataSource.getConnection();
+            if(descriptor.getConnectionSupplier() != null) {
+                c = descriptor.getConnectionSupplier().get();
+            } else {
+                c = dataSource.getConnection();
+            }
             addConnection(connectionName, c);
         }
 
@@ -219,19 +223,18 @@
 
     protected Connection addConnection(String connectionName, Connection connection) {
 
-        if(descriptor.getIsolation() != TransactionDescriptor.ISOLATION_DEFAULT) {
-            try {
-                defaultIsolationLevel = connection.getTransactionIsolation();
-                connection.setTransactionIsolation(descriptor.getIsolation());
-            } catch (SQLException ex) {
-                throw new CayenneRuntimeException("Unable to set required isolation level: " + descriptor.getIsolation(), ex);
-            }
-        }
+        setIsolationLevelFrom(connection);
 
-        TransactionConnectionDecorator wrapper = new TransactionConnectionDecorator(connection);
+        TransactionConnectionDecorator wrapper = null;
 
         if (listeners != null) {
             for (TransactionListener listener : listeners) {
+                connection = listener.decorateConnection(this, connection);
+            }
+
+            wrapper = new TransactionConnectionDecorator(connection);
+
+            for (TransactionListener listener : listeners) {
                 listener.willAddConnection(this, connectionName, wrapper);
             }
         }
@@ -241,6 +244,10 @@
             connections = new HashMap<>();
         }
 
+        if (wrapper == null) {
+            wrapper = new TransactionConnectionDecorator(connection);
+        }
+
         if (connections.put(connectionName, wrapper) != wrapper) {
             connectionAdded(connection);
         }
@@ -248,6 +255,17 @@
         return wrapper;
     }
 
+    private void setIsolationLevelFrom(Connection connection) {
+        if (descriptor.getIsolation() != TransactionDescriptor.ISOLATION_DEFAULT) {
+            try {
+                defaultIsolationLevel = connection.getTransactionIsolation();
+                connection.setTransactionIsolation(descriptor.getIsolation());
+            } catch (SQLException ex) {
+                throw new CayenneRuntimeException("Unable to set required isolation level: " + descriptor.getIsolation(), ex);
+            }
+        }
+    }
+
     protected void connectionAdded(Connection connection) {
 
         // implicitly begin transaction
@@ -278,7 +296,7 @@
                 // ignore for now
             } finally {
                 // restore connection default isolation level ...
-                if(defaultIsolationLevel != -1) {
+                if (defaultIsolationLevel != -1) {
                     try {
                         c.setTransactionIsolation(defaultIsolationLevel);
                     } catch (SQLException ignore) {
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/tx/TransactionDescriptor.java b/cayenne-server/src/main/java/org/apache/cayenne/tx/TransactionDescriptor.java
index 7dd60ce..734132a 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/tx/TransactionDescriptor.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/tx/TransactionDescriptor.java
@@ -19,10 +19,19 @@
 
 package org.apache.cayenne.tx;
 
+import java.sql.Connection;
+import java.util.function.Supplier;
+
 /**
- *
- * Descriptor that provide desired transaction isolation level and propagation logic.
- *
+ * Descriptor that allows to customize transaction logic.
+ * It provides following options:
+ * <ul>
+ *  <li> transaction isolation level
+ *  <li> transaction propagation logic.
+ *  <li> custom connection to use in a transaction
+ * </ul>
+ * @see TransactionManager#performInTransaction(TransactionalOperation, TransactionDescriptor)
+ * @see org.apache.cayenne.configuration.server.ServerRuntime#performInTransaction(TransactionalOperation, TransactionDescriptor)
  * @since 4.1
  */
 public class TransactionDescriptor {
@@ -32,47 +41,54 @@
      */
     public static final int ISOLATION_DEFAULT = -1;
 
-    private final int isolation;
+    private int isolation;
 
-    private final TransactionPropagation propagation;
+    private TransactionPropagation propagation;
+
+    private Supplier<Connection> connectionSupplier;
+
+    private TransactionDescriptor() {
+    }
 
     /**
-     * @param isolation one of the following <code>Connection</code> constants:
-     *        <code>Connection.TRANSACTION_READ_UNCOMMITTED</code>,
-     *        <code>Connection.TRANSACTION_READ_COMMITTED</code>,
-     *        <code>Connection.TRANSACTION_REPEATABLE_READ</code>,
-     *        <code>Connection.TRANSACTION_SERIALIZABLE</code>, or
-     *        <code>TransactionDescriptor.ISOLATION_DEFAULT</code>
-     *
+     * @param isolation   one of the following <code>Connection</code> constants:
+     *                    <code>Connection.TRANSACTION_READ_UNCOMMITTED</code>,
+     *                    <code>Connection.TRANSACTION_READ_COMMITTED</code>,
+     *                    <code>Connection.TRANSACTION_REPEATABLE_READ</code>,
+     *                    <code>Connection.TRANSACTION_SERIALIZABLE</code>, or
+     *                    <code>TransactionDescriptor.ISOLATION_DEFAULT</code>
      * @param propagation transaction propagation behaviour
-     *
      * @see TransactionPropagation
+     * @deprecated since 4.2. Use {@link #builder()} method instead.
      */
+    @Deprecated
     public TransactionDescriptor(int isolation, TransactionPropagation propagation) {
         this.isolation = isolation;
         this.propagation = propagation;
     }
 
     /**
-     *
      * Create transaction descriptor with desired isolation level and <code>NESTED</code> propagation
      *
      * @param isolation one of the following <code>Connection</code> constants:
-     *        <code>Connection.TRANSACTION_READ_UNCOMMITTED</code>,
-     *        <code>Connection.TRANSACTION_READ_COMMITTED</code>,
-     *        <code>Connection.TRANSACTION_REPEATABLE_READ</code>,
-     *        <code>Connection.TRANSACTION_SERIALIZABLE</code>, or
-     *        <code>TransactionDescriptor.ISOLATION_DEFAULT</code>
+     *                  <code>Connection.TRANSACTION_READ_UNCOMMITTED</code>,
+     *                  <code>Connection.TRANSACTION_READ_COMMITTED</code>,
+     *                  <code>Connection.TRANSACTION_REPEATABLE_READ</code>,
+     *                  <code>Connection.TRANSACTION_SERIALIZABLE</code>, or
+     *                  <code>TransactionDescriptor.ISOLATION_DEFAULT</code>
+     * @deprecated since 4.2. Use {@link #builder()} method instead.
      */
+    @Deprecated
     public TransactionDescriptor(int isolation) {
         this(isolation, TransactionPropagation.NESTED);
     }
 
     /**
-     *
      * @param propagation transaction propagation behaviour
      * @see TransactionPropagation
+     * @deprecated since 4.2. Use {@link #builder()} method instead.
      */
+    @Deprecated
     public TransactionDescriptor(TransactionPropagation propagation) {
         this(ISOLATION_DEFAULT, propagation);
     }
@@ -90,4 +106,76 @@
     public TransactionPropagation getPropagation() {
         return propagation;
     }
+
+    /**
+     * @return custom connection supplier, passed by user
+     */
+    public Supplier<Connection> getConnectionSupplier() {
+        return connectionSupplier;
+    }
+
+    public static Builder builder(){
+        return new Builder();
+    }
+
+    /**
+     * Builder class for the TransactionDescriptor.
+     */
+    public static class Builder {
+        private final TransactionDescriptor transactionDescriptor = new TransactionDescriptor();
+
+        private Builder(){
+        }
+
+        /**
+         * @param isolation one of the following <code>Connection</code> constants:
+         *                  <code>Connection.TRANSACTION_READ_UNCOMMITTED</code>,
+         *                  <code>Connection.TRANSACTION_READ_COMMITTED</code>,
+         *                  <code>Connection.TRANSACTION_REPEATABLE_READ</code>,
+         *                  <code>Connection.TRANSACTION_SERIALIZABLE</code>, or
+         *                  <code>TransactionDescriptor.ISOLATION_DEFAULT</code>
+         */
+        public Builder isolation(int isolation) {
+            transactionDescriptor.isolation = isolation;
+            return this;
+        }
+
+        /**
+         * A custom connection provided by the TransactionDescriptor will be used
+         * instead of any other connection provided by tbe connection pool.
+         *
+         * @param connection custom connection
+         * @see #connectionSupplier(Supplier)
+         */
+        public Builder connection(Connection connection) {
+            transactionDescriptor.connectionSupplier = () -> connection;
+            return this;
+        }
+
+        /**
+         * A custom connection provided by the TransactionDescriptor will be used
+         * instead of any other connection provided by tbe connection pool.
+         *
+         * @param connectionSupplier custom connection supplier
+         * @see #connection(Connection)
+         */
+        public Builder connectionSupplier(Supplier<Connection> connectionSupplier){
+            transactionDescriptor.connectionSupplier = connectionSupplier;
+            return this;
+        }
+
+        /**
+         * @param propagation transaction propagation behaviour
+         * @see TransactionPropagation
+         */
+        public Builder propagation(TransactionPropagation propagation) {
+            transactionDescriptor.propagation = propagation;
+            return this;
+        }
+
+        public TransactionDescriptor build() {
+            return transactionDescriptor;
+        }
+    }
+
 }
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/tx/TransactionListener.java b/cayenne-server/src/main/java/org/apache/cayenne/tx/TransactionListener.java
index dc230e1..14b55ad 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/tx/TransactionListener.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/tx/TransactionListener.java
@@ -33,4 +33,20 @@
     void willRollback(Transaction tx);
 
     void willAddConnection(Transaction tx, String connectionName, Connection connection);
+
+    /**
+     * This method could be used to decorate or substitute
+     * new connection initiated inside a Cayenne transaction.
+     * <br/>
+     * The default implementation returns the same connection.
+     *
+     * @param tx transaction that initiated connection
+     * @param connection connection (it could be decorated by other listeners)
+     * @return connection
+     *
+     * @since 4.2
+     */
+    default Connection decorateConnection(Transaction tx, Connection connection){
+        return connection;
+    }
 }
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelIT.java
index 229031e..471955f 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelIT.java
@@ -49,6 +49,18 @@
     }
 
     @Test
+    public void testAdd() {
+        ArtGroup parentGroup = context.newObject(ArtGroup.class);
+        parentGroup.setName("parent");
+
+        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
+        childGroup1.setName("child1");
+        childGroup1.setToParentGroup(parentGroup);
+
+        context.commitChanges();
+    }
+
+    @Test
     public void testAddDeleteWithCommit() {
         ArtGroup parentGroup = context.newObject(ArtGroup.class);
         parentGroup.setName("parent");
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/IdentityColumnsIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/IdentityColumnsIT.java
index 1a71fe8..fdd33e0 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/IdentityColumnsIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/IdentityColumnsIT.java
@@ -39,6 +39,7 @@
 import org.apache.cayenne.testdo.generated.GeneratedColumnTestEntity;
 import org.apache.cayenne.testdo.generated.GeneratedF1;
 import org.apache.cayenne.testdo.generated.GeneratedF2;
+import org.apache.cayenne.testdo.generated.GeneratedReflexive;
 import org.apache.cayenne.unit.di.server.CayenneProjects;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
@@ -339,4 +340,32 @@
         assertNotNull(Cayenne.objectForPK(context, GeneratedColumnTestEntity.class, id1));
         assertNotNull(Cayenne.objectForPK(context, GeneratedColumnDep.class, id2));
     }
+
+    @Test
+    public void testReflexiveDep() {
+
+        GeneratedReflexive reflexive3 = context.newObject(GeneratedReflexive.class);
+        reflexive3.setName("3");
+
+        GeneratedReflexive reflexive2 = context.newObject(GeneratedReflexive.class);
+        reflexive2.setName("2");
+
+        GeneratedReflexive reflexive4 = context.newObject(GeneratedReflexive.class);
+        reflexive4.setName("4");
+
+        GeneratedReflexive reflexive1 = context.newObject(GeneratedReflexive.class);
+        reflexive1.setName("1");
+
+        reflexive1.setNext(reflexive2);
+        reflexive2.setNext(reflexive3);
+        reflexive3.setNext(reflexive4);
+
+        context.commitChanges();
+
+        reflexive1.setNext(null);
+        reflexive2.setNext(null);
+        reflexive3.setNext(null);
+
+        context.commitChanges();
+    }
 }
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeIT.java b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeIT.java
index dc4740e..4ab5c26 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeIT.java
@@ -37,9 +37,7 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.*;
 
 @UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
 public class ServerRuntimeIT extends ServerCase {
@@ -50,10 +48,34 @@
     @Inject
     private ObjectContext context;
 
+    class DefaultListenerImpl implements TransactionListener{
+
+        @Override
+        public void willCommit(Transaction tx) {
+
+        }
+
+        @Override
+        public void willRollback(Transaction tx) {
+
+        }
+
+        @Override
+        public void willAddConnection(Transaction tx, String connectionName, Connection connection) {
+
+        }
+
+        @Override
+        public Connection decorateConnection(Transaction tx, Connection connection) {
+            return connection;
+        }
+    }
+
     @Test
     public void testPerformInTransaction_Local_Callback() {
 
-        TransactionListener callback = mock(TransactionListener.class);
+        TransactionListener callback = mock(DefaultListenerImpl.class);
+        when(callback.decorateConnection(any(Transaction.class),any(Connection.class))).thenCallRealMethod();
 
         Artist a = runtime.performInTransaction(new TransactionalOperation<Artist>() {
 
@@ -72,12 +94,14 @@
         verify(callback).willCommit(any(Transaction.class));
         verify(callback).willAddConnection(any(Transaction.class), any(String.class), any(Connection.class));
         verify(callback, times(0)).willRollback(any(Transaction.class));
+        verify(callback).decorateConnection(any(Transaction.class),any(Connection.class));
     }
 
     @Test
     public void testPerformInTransaction_Local_Callback_Rollback() {
 
         TransactionListener callback = mock(TransactionListener.class);
+        when(callback.decorateConnection(any(Transaction.class),any(Connection.class))).thenCallRealMethod();
 
         try {
             runtime.performInTransaction(new TransactionalOperation<Artist>() {
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTObjPathEnumIT.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTObjPathEnumIT.java
new file mode 100644
index 0000000..02bf202
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTObjPathEnumIT.java
@@ -0,0 +1,41 @@
+package org.apache.cayenne.exp.parser;
+
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.testdo.enum_test.Enum1;
+import org.apache.cayenne.testdo.enum_test.EnumEntity;
+import org.apache.cayenne.unit.di.server.CayenneProjects;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+@UseServerRuntime(CayenneProjects.ENUM_PROJECT)
+public class ASTObjPathEnumIT extends ServerCase {
+
+    @Inject
+    private ObjectContext context;
+
+    @Test
+    public void testInjectEnumByName() {
+        ASTObjPath node = new ASTObjPath("enumAttribute");
+
+        EnumEntity enumEntity = context.newObject(EnumEntity.class);
+        assertNull(enumEntity.getEnumAttribute());
+
+        node.injectValue(enumEntity, "one");
+        assertEquals(Enum1.one, enumEntity.getEnumAttribute());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testInjectUnknownEnumByName() {
+        ASTObjPath node = new ASTObjPath("enumAttribute");
+
+        EnumEntity enumEntity = context.newObject(EnumEntity.class);
+        assertNull(enumEntity.getEnumAttribute());
+
+        node.injectValue(enumEntity, "four");
+    }
+}
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTObjPathTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTObjPathTest.java
index 44c908c..98eda89 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTObjPathTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTObjPathTest.java
@@ -19,9 +19,12 @@
 package org.apache.cayenne.exp.parser;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 
 import java.io.IOException;
 
+import org.apache.cayenne.testdo.enum_test.Enum1;
+import org.apache.cayenne.testdo.enum_test.EnumEntity;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.unit.util.TstBean;
 import org.junit.Test;
@@ -75,4 +78,16 @@
 		b2.setProperty2(-3);
 		assertEquals(-3, node.evaluate(b2));
 	}
+
+	@Test
+	public void testInjectDataObject() {
+		ASTObjPath node = new ASTObjPath("artistName");
+
+		Artist artist = new Artist();
+		assertNull(artist.getArtistName());
+
+		node.injectValue(artist, "test");
+		assertEquals("test", artist.getArtistName());
+	}
+
 }
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/GeneratedReflexive.java b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/GeneratedReflexive.java
new file mode 100644
index 0000000..7f7fec1
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/GeneratedReflexive.java
@@ -0,0 +1,9 @@
+package org.apache.cayenne.testdo.generated;
+
+import org.apache.cayenne.testdo.generated.auto._GeneratedReflexive;
+
+public class GeneratedReflexive extends _GeneratedReflexive {
+
+    private static final long serialVersionUID = 1L;
+
+}
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnCompKey.java b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnCompKey.java
index 79435a2..cbe6ba9 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnCompKey.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnCompKey.java
@@ -5,9 +5,7 @@
 import java.io.ObjectOutputStream;
 
 import org.apache.cayenne.BaseDataObject;
-import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.exp.property.EntityProperty;
-import org.apache.cayenne.exp.property.NumericProperty;
 import org.apache.cayenne.exp.property.PropertyFactory;
 import org.apache.cayenne.exp.property.StringProperty;
 import org.apache.cayenne.testdo.generated.GeneratedColumnCompMaster;
@@ -20,13 +18,10 @@
  */
 public abstract class _GeneratedColumnCompKey extends BaseDataObject {
 
-    private static final long serialVersionUID = 1L; 
+    private static final long serialVersionUID = 1L;
 
-    public static final NumericProperty<Integer> AUTO_PK_PK_PROPERTY = PropertyFactory.createNumeric(ExpressionFactory.dbPathExp("AUTO_PK"), Integer.class);
     public static final String AUTO_PK_PK_COLUMN = "AUTO_PK";
-    public static final NumericProperty<Integer> GENERATED_COLUMN_PK_PROPERTY = PropertyFactory.createNumeric(ExpressionFactory.dbPathExp("GENERATED_COLUMN"), Integer.class);
     public static final String GENERATED_COLUMN_PK_COLUMN = "GENERATED_COLUMN";
-    public static final NumericProperty<Integer> PROPAGATED_PK_PK_PROPERTY = PropertyFactory.createNumeric(ExpressionFactory.dbPathExp("PROPAGATED_PK"), Integer.class);
     public static final String PROPAGATED_PK_PK_COLUMN = "PROPAGATED_PK";
 
     public static final StringProperty<String> NAME = PropertyFactory.createString("name", String.class);
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnCompMaster.java b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnCompMaster.java
index 13b3a09..937d393 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnCompMaster.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnCompMaster.java
@@ -6,9 +6,7 @@
 import java.util.List;
 
 import org.apache.cayenne.BaseDataObject;
-import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.exp.property.ListProperty;
-import org.apache.cayenne.exp.property.NumericProperty;
 import org.apache.cayenne.exp.property.PropertyFactory;
 import org.apache.cayenne.exp.property.StringProperty;
 import org.apache.cayenne.testdo.generated.GeneratedColumnCompKey;
@@ -21,9 +19,8 @@
  */
 public abstract class _GeneratedColumnCompMaster extends BaseDataObject {
 
-    private static final long serialVersionUID = 1L; 
+    private static final long serialVersionUID = 1L;
 
-    public static final NumericProperty<Integer> ID_PK_PROPERTY = PropertyFactory.createNumeric(ExpressionFactory.dbPathExp("ID"), Integer.class);
     public static final String ID_PK_COLUMN = "ID";
 
     public static final StringProperty<String> NAME = PropertyFactory.createString("name", String.class);
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnDep.java b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnDep.java
index d647e25..4de74b8 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnDep.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnDep.java
@@ -5,9 +5,7 @@
 import java.io.ObjectOutputStream;
 
 import org.apache.cayenne.BaseDataObject;
-import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.exp.property.EntityProperty;
-import org.apache.cayenne.exp.property.NumericProperty;
 import org.apache.cayenne.exp.property.PropertyFactory;
 import org.apache.cayenne.exp.property.StringProperty;
 import org.apache.cayenne.testdo.generated.GeneratedColumnTestEntity;
@@ -20,9 +18,8 @@
  */
 public abstract class _GeneratedColumnDep extends BaseDataObject {
 
-    private static final long serialVersionUID = 1L; 
+    private static final long serialVersionUID = 1L;
 
-    public static final NumericProperty<Integer> GENERATED_COLUMN_FK_PK_PROPERTY = PropertyFactory.createNumeric(ExpressionFactory.dbPathExp("GENERATED_COLUMN_FK"), Integer.class);
     public static final String GENERATED_COLUMN_FK_PK_COLUMN = "GENERATED_COLUMN_FK";
 
     public static final StringProperty<String> NAME = PropertyFactory.createString("name", String.class);
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnTest2.java b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnTest2.java
index 6d1d7af..f12ad6a 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnTest2.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnTest2.java
@@ -5,8 +5,6 @@
 import java.io.ObjectOutputStream;
 
 import org.apache.cayenne.BaseDataObject;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.exp.property.NumericProperty;
 import org.apache.cayenne.exp.property.PropertyFactory;
 import org.apache.cayenne.exp.property.StringProperty;
 
@@ -18,9 +16,8 @@
  */
 public abstract class _GeneratedColumnTest2 extends BaseDataObject {
 
-    private static final long serialVersionUID = 1L; 
+    private static final long serialVersionUID = 1L;
 
-    public static final NumericProperty<Integer> GENERATED_COLUMN_PK_PROPERTY = PropertyFactory.createNumeric(ExpressionFactory.dbPathExp("GENERATED_COLUMN"), Integer.class);
     public static final String GENERATED_COLUMN_PK_COLUMN = "GENERATED_COLUMN";
 
     public static final StringProperty<String> NAME = PropertyFactory.createString("name", String.class);
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnTestEntity.java b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnTestEntity.java
index 6e7283d..1e7cc3c 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnTestEntity.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedColumnTestEntity.java
@@ -5,9 +5,7 @@
 import java.io.ObjectOutputStream;
 
 import org.apache.cayenne.BaseDataObject;
-import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.exp.property.EntityProperty;
-import org.apache.cayenne.exp.property.NumericProperty;
 import org.apache.cayenne.exp.property.PropertyFactory;
 import org.apache.cayenne.exp.property.StringProperty;
 import org.apache.cayenne.testdo.generated.GeneratedColumnDep;
@@ -20,9 +18,8 @@
  */
 public abstract class _GeneratedColumnTestEntity extends BaseDataObject {
 
-    private static final long serialVersionUID = 1L; 
+    private static final long serialVersionUID = 1L;
 
-    public static final NumericProperty<Integer> GENERATED_COLUMN_PK_PROPERTY = PropertyFactory.createNumeric(ExpressionFactory.dbPathExp("GENERATED_COLUMN"), Integer.class);
     public static final String GENERATED_COLUMN_PK_COLUMN = "GENERATED_COLUMN";
 
     public static final StringProperty<String> NAME = PropertyFactory.createString("name", String.class);
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedF1.java b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedF1.java
index 0749b4b..1c8d52a 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedF1.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedF1.java
@@ -6,9 +6,7 @@
 import java.util.List;
 
 import org.apache.cayenne.CayenneDataObject;
-import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.exp.property.ListProperty;
-import org.apache.cayenne.exp.property.NumericProperty;
 import org.apache.cayenne.exp.property.PropertyFactory;
 import org.apache.cayenne.testdo.generated.GeneratedF2;
 
@@ -20,9 +18,8 @@
  */
 public abstract class _GeneratedF1 extends CayenneDataObject {
 
-    private static final long serialVersionUID = 1L; 
+    private static final long serialVersionUID = 1L;
 
-    public static final NumericProperty<Integer> ID_PK_PROPERTY = PropertyFactory.createNumeric(ExpressionFactory.dbPathExp("ID"), Integer.class);
     public static final String ID_PK_COLUMN = "ID";
 
     public static final ListProperty<GeneratedF2> F2 = PropertyFactory.createList("f2", GeneratedF2.class);
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedF2.java b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedF2.java
index 0716c67..8c0caaa 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedF2.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedF2.java
@@ -6,9 +6,7 @@
 import java.util.List;
 
 import org.apache.cayenne.CayenneDataObject;
-import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.exp.property.ListProperty;
-import org.apache.cayenne.exp.property.NumericProperty;
 import org.apache.cayenne.exp.property.PropertyFactory;
 import org.apache.cayenne.testdo.generated.GeneratedF1;
 
@@ -20,9 +18,8 @@
  */
 public abstract class _GeneratedF2 extends CayenneDataObject {
 
-    private static final long serialVersionUID = 1L; 
+    private static final long serialVersionUID = 1L;
 
-    public static final NumericProperty<Integer> ID_PK_PROPERTY = PropertyFactory.createNumeric(ExpressionFactory.dbPathExp("ID"), Integer.class);
     public static final String ID_PK_COLUMN = "ID";
 
     public static final ListProperty<GeneratedF1> F1 = PropertyFactory.createList("f1", GeneratedF1.class);
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedReflexive.java b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedReflexive.java
new file mode 100644
index 0000000..b360c99
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/testdo/generated/auto/_GeneratedReflexive.java
@@ -0,0 +1,106 @@
+package org.apache.cayenne.testdo.generated.auto;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.cayenne.CayenneDataObject;
+import org.apache.cayenne.exp.property.EntityProperty;
+import org.apache.cayenne.exp.property.PropertyFactory;
+import org.apache.cayenne.exp.property.StringProperty;
+import org.apache.cayenne.testdo.generated.GeneratedReflexive;
+
+/**
+ * Class _GeneratedReflexive was generated by Cayenne.
+ * It is probably a good idea to avoid changing this class manually,
+ * since it may be overwritten next time code is regenerated.
+ * If you need to make any customizations, please use subclass.
+ */
+public abstract class _GeneratedReflexive extends CayenneDataObject {
+
+    private static final long serialVersionUID = 1L;
+
+    public static final String ID_PK_COLUMN = "ID";
+
+    public static final StringProperty<String> NAME = PropertyFactory.createString("name", String.class);
+    public static final EntityProperty<GeneratedReflexive> NEXT = PropertyFactory.createEntity("next", GeneratedReflexive.class);
+
+    protected String name;
+
+    protected Object next;
+
+    public void setName(String name) {
+        beforePropertyWrite("name", this.name, name);
+        this.name = name;
+    }
+
+    public String getName() {
+        beforePropertyRead("name");
+        return this.name;
+    }
+
+    public void setNext(GeneratedReflexive next) {
+        setToOneTarget("next", next, true);
+    }
+
+    public GeneratedReflexive getNext() {
+        return (GeneratedReflexive)readProperty("next");
+    }
+
+    @Override
+    public Object readPropertyDirectly(String propName) {
+        if(propName == null) {
+            throw new IllegalArgumentException();
+        }
+
+        switch(propName) {
+            case "name":
+                return this.name;
+            case "next":
+                return this.next;
+            default:
+                return super.readPropertyDirectly(propName);
+        }
+    }
+
+    @Override
+    public void writePropertyDirectly(String propName, Object val) {
+        if(propName == null) {
+            throw new IllegalArgumentException();
+        }
+
+        switch (propName) {
+            case "name":
+                this.name = (String)val;
+                break;
+            case "next":
+                this.next = val;
+                break;
+            default:
+                super.writePropertyDirectly(propName, val);
+        }
+    }
+
+    private void writeObject(ObjectOutputStream out) throws IOException {
+        writeSerialized(out);
+    }
+
+    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+        readSerialized(in);
+    }
+
+    @Override
+    protected void writeState(ObjectOutputStream out) throws IOException {
+        super.writeState(out);
+        out.writeObject(this.name);
+        out.writeObject(this.next);
+    }
+
+    @Override
+    protected void readState(ObjectInputStream in) throws IOException, ClassNotFoundException {
+        super.readState(in);
+        this.name = (String)in.readObject();
+        this.next = in.readObject();
+    }
+
+}
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/tx/DefaultTransactionManagerIT.java b/cayenne-server/src/test/java/org/apache/cayenne/tx/DefaultTransactionManagerIT.java
index deb025a..276b258 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/tx/DefaultTransactionManagerIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/tx/DefaultTransactionManagerIT.java
@@ -83,10 +83,12 @@
         try {
             final Object expectedResult = new Object();
             Object result = txManager.performInTransaction(() -> {
-                    assertSame(tx, BaseTransaction.getThreadTransaction());
-                    return expectedResult;
-                },
-                new TransactionDescriptor(TransactionPropagation.NESTED)
+                        assertSame(tx, BaseTransaction.getThreadTransaction());
+                        return expectedResult;
+                    },
+                    TransactionDescriptor.builder()
+                            .propagation(TransactionPropagation.NESTED)
+                            .build()
             );
             assertSame(expectedResult, result);
         } finally {
@@ -109,7 +111,9 @@
                         assertSame(tx, BaseTransaction.getThreadTransaction());
                         return expectedResult;
                     },
-                    new TransactionDescriptor(TransactionPropagation.MANDATORY)
+                    TransactionDescriptor.builder()
+                            .propagation(TransactionPropagation.MANDATORY)
+                            .build()
             );
             assertSame(expectedResult, result);
         } finally {
@@ -133,7 +137,9 @@
                         assertSame(tx, BaseTransaction.getThreadTransaction());
                         return expectedResult;
                     },
-                    new TransactionDescriptor(TransactionPropagation.MANDATORY)
+                    TransactionDescriptor.builder()
+                            .propagation(TransactionPropagation.MANDATORY)
+                            .build()
             );
             assertSame(expectedResult, result);
         } finally {
@@ -163,7 +169,9 @@
                         assertSame(tx2, BaseTransaction.getThreadTransaction());
                         return expectedResult;
                     },
-                    new TransactionDescriptor(TransactionPropagation.REQUIRES_NEW)
+                    TransactionDescriptor.builder()
+                            .propagation(TransactionPropagation.REQUIRES_NEW)
+                            .build()
             );
             assertSame(expectedResult, result);
             assertSame(tx1, BaseTransaction.getThreadTransaction());
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/tx/TransactionCustomConnectionIT.java b/cayenne-server/src/test/java/org/apache/cayenne/tx/TransactionCustomConnectionIT.java
new file mode 100644
index 0000000..7c73a38
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/tx/TransactionCustomConnectionIT.java
@@ -0,0 +1,226 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.tx;
+
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.log.JdbcEventLogger;
+import org.apache.cayenne.query.ObjectSelect;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.unit.di.server.CayenneProjects;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+/**
+ * Check if connection can be decorated with listeners and that default connection of TransactionDescriptor
+ * has major priority
+ *
+ * @see BaseTransaction,TransactionDescriptor
+ * @since 4.2
+ */
+@UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
+public class TransactionCustomConnectionIT extends ServerCase {
+
+    private final Logger logger = LoggerFactory.getLogger(TransactionIsolationIT.class);
+
+    @Inject
+    DataContext context;
+
+    @Inject
+    ServerRuntime runtime;
+
+    @Inject
+    private JdbcEventLogger jdbcEventLogger;
+
+    TransactionManager manager;
+    private static boolean firstReadonlyCondition;
+
+    @Before
+    public void initTransactionManager() {
+        // no binding in test container, get it from runtime
+        manager = runtime.getInjector().getInstance(TransactionManager.class);
+    }
+
+    /**
+     * Test depends on decoration of readonly property of the connection, but not every driver supports readonly setting.
+     * So this test calculated for drivers with current support, but if it is not supported, this test mustn't fail
+     * because it checks if readonly wasn't changed by setter and changes firstReadonlyCondition flag value
+     * if it is true to avoid fails. In that case test is useless, but it's behavior in other cases can submit
+     * right behavior of methods
+     */
+    @Test
+    public void testConnectionDecorationWithListeners() {
+        Transaction t = new CayenneTransaction(jdbcEventLogger);
+        //add listeners which will check if connection object will be changed after every decorate call
+        List<TransactionListener> listeners = addAndGetListenersWithCustomReadonlyTo(t);
+        BaseTransaction.bindThreadTransaction(t);
+        try {
+            ObjectSelect.query(Artist.class).select(context);
+
+            //check if the last listener set readonly property to false
+            t.getConnections().forEach((key, connection) -> {
+                try {
+                    assertEquals(connection.isReadOnly(), firstReadonlyCondition);
+                } catch (SQLException throwables) {
+                    throwables.printStackTrace();
+                }
+            });
+
+            //check if every decoration from listener was called
+            for (TransactionListener transactionListener : listeners) {
+                verify(transactionListener).decorateConnection(any(), any());
+            }
+        } finally {
+            BaseTransaction.bindThreadTransaction(null);
+            t.commit();
+        }
+    }
+
+    private List<TransactionListener> addAndGetListenersWithCustomReadonlyTo(Transaction t) {
+        Class<?>[] classes = new Class[]{ListenerWithFirstReadonlyDecorator.class, ListenerWithSecondReadonlyDecorator.class};
+        List<TransactionListener> listeners = new ArrayList<>();
+        for (Class<?> aClass : classes) {
+            TransactionListener listener = (TransactionListener) mock(aClass);
+            listeners.add(listener);
+            when(listener.decorateConnection(any(), any())).thenCallRealMethod();
+            t.addListener(listener);
+        }
+        return listeners;
+    }
+
+    //listener, which will check if readonly property of connection is false and set it to true
+    class ListenerWithFirstReadonlyDecorator implements TransactionListener {
+
+        @Override
+        public void willCommit(Transaction tx) {
+
+        }
+
+        @Override
+        public void willRollback(Transaction tx) {
+
+        }
+
+        @Override
+        public void willAddConnection(Transaction tx, String connectionName, Connection connection) {
+
+        }
+
+        @Override
+        public Connection decorateConnection(Transaction tx, Connection connection) {
+            try {
+                firstReadonlyCondition = connection.isReadOnly();
+                connection.setReadOnly(!firstReadonlyCondition);
+
+                if (connection.isReadOnly() == firstReadonlyCondition) {
+                    firstReadonlyCondition = !connection.isReadOnly();
+                }
+            } catch (SQLException throwables) {
+                throwables.printStackTrace();
+            }
+            return connection;
+        }
+    }
+
+    //listener, which will check if readonly property of connection is true and set it to false
+    class ListenerWithSecondReadonlyDecorator implements TransactionListener {
+
+        @Override
+        public void willCommit(Transaction tx) {
+
+        }
+
+        @Override
+        public void willRollback(Transaction tx) {
+
+        }
+
+        @Override
+        public void willAddConnection(Transaction tx, String connectionName, Connection connection) {
+
+        }
+
+        @Override
+        public Connection decorateConnection(Transaction tx, Connection connection) {
+            try {
+                assertEquals(!firstReadonlyCondition, connection.isReadOnly());
+                connection.setReadOnly(!connection.isReadOnly());
+                if (connection.isReadOnly() == !firstReadonlyCondition) {
+                    firstReadonlyCondition = !firstReadonlyCondition;
+                }
+            } catch (SQLException throwables) {
+                throwables.printStackTrace();
+            }
+            return connection;
+        }
+    }
+
+    @Test
+    public void testDefaultConnectionInDescriptor() {
+        Transaction t = new CayenneTransaction(jdbcEventLogger);
+        BaseTransaction.bindThreadTransaction(t);
+        try {
+            ObjectSelect.query(Artist.class).select(context);
+            Connection connection = t.getConnections().values().stream().findFirst().get();
+
+            try {
+                connection.setAutoCommit(true);
+            } catch (SQLException throwables) {
+                throwables.printStackTrace();
+            }
+
+            TransactionDescriptor mockDescriptor = mock(TransactionDescriptor.class);
+            when(mockDescriptor.getConnectionSupplier()).thenReturn(() -> connection);
+            when(mockDescriptor.getPropagation()).thenReturn(TransactionPropagation.REQUIRES_NEW);
+            when(mockDescriptor.getIsolation()).thenReturn(Connection.TRANSACTION_SERIALIZABLE);
+
+            performInTransaction(mockDescriptor);
+            verify(mockDescriptor, times(2)).getConnectionSupplier();
+        } finally {
+            BaseTransaction.bindThreadTransaction(null);
+            t.commit();
+        }
+
+    }
+
+    private void performInTransaction(TransactionDescriptor descriptor) {
+        Artist artist = context.newObject(Artist.class);
+        artist.setArtistName("test");
+        manager.performInTransaction(() -> {
+            artist.setArtistName("test3");
+            context.commitChanges();
+            return null;
+        }, descriptor);
+    }
+}
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/tx/TransactionIsolationIT.java b/cayenne-server/src/test/java/org/apache/cayenne/tx/TransactionIsolationIT.java
index 6f6cfbb..3bdefee 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/tx/TransactionIsolationIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/tx/TransactionIsolationIT.java
@@ -74,10 +74,10 @@
             return;
         }
 
-        TransactionDescriptor descriptor = new TransactionDescriptor(
-                Connection.TRANSACTION_SERIALIZABLE,
-                TransactionPropagation.REQUIRES_NEW
-        );
+        TransactionDescriptor descriptor = TransactionDescriptor.builder()
+                .propagation(TransactionPropagation.REQUIRES_NEW)
+                .isolation(Connection.TRANSACTION_SERIALIZABLE)
+                .build();
 
         CountDownLatch startSignal = new CountDownLatch(1);
         CountDownLatch resumeSerializableTransaction = new CountDownLatch(1);
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/tx/TransactionPropagationRollbackIT.java b/cayenne-server/src/test/java/org/apache/cayenne/tx/TransactionPropagationRollbackIT.java
index 6c8985e..8306d2e 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/tx/TransactionPropagationRollbackIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/tx/TransactionPropagationRollbackIT.java
@@ -69,10 +69,10 @@
      */
     @Test
     public void testPropagationRequiresNew() {
-        TransactionDescriptor descriptor = new TransactionDescriptor(
-                Connection.TRANSACTION_SERIALIZABLE, // ensure that transaction not visible to each other
-                TransactionPropagation.REQUIRES_NEW  // require new transaction for every operation
-        );
+        TransactionDescriptor descriptor = TransactionDescriptor.builder()
+                .propagation(TransactionPropagation.REQUIRES_NEW)
+                .isolation(Connection.TRANSACTION_SERIALIZABLE)
+                .build();
 
         performInTransaction(descriptor);
 
@@ -89,10 +89,10 @@
     @Test
     public void testPropagationNested() {
 
-        TransactionDescriptor descriptor = new TransactionDescriptor(
-                Connection.TRANSACTION_SERIALIZABLE, // ensure that transaction not visible to each other
-                TransactionPropagation.NESTED        // allow joining to existing transaction
-        );
+        TransactionDescriptor descriptor = TransactionDescriptor.builder()
+                .isolation(Connection.TRANSACTION_SERIALIZABLE)
+                .propagation(TransactionPropagation.NESTED)
+                .build();
 
         performInTransaction(descriptor);
 
@@ -109,10 +109,10 @@
     @Test
     public void testPropagationMandatory() {
 
-        TransactionDescriptor descriptor = new TransactionDescriptor(
-                Connection.TRANSACTION_SERIALIZABLE, // ensure that transaction not visible to each other
-                TransactionPropagation.MANDATORY     // requires existing transaction to join
-        );
+        TransactionDescriptor descriptor = TransactionDescriptor.builder()
+                .isolation(Connection.TRANSACTION_SERIALIZABLE)
+                .propagation(TransactionPropagation.MANDATORY)
+                .build();
 
         performInTransaction(descriptor);
 
diff --git a/cayenne-server/src/test/resources/cayenne-generated.xml b/cayenne-server/src/test/resources/cayenne-generated.xml
index 5742090..9f684cc 100644
--- a/cayenne-server/src/test/resources/cayenne-generated.xml
+++ b/cayenne-server/src/test/resources/cayenne-generated.xml
@@ -1,5 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <domain xmlns="http://cayenne.apache.org/schema/10/domain"
+	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	 xsi:schemaLocation="http://cayenne.apache.org/schema/10/domain https://cayenne.apache.org/schema/10/domain.xsd"
 	 project-version="10">
 	<map name="generated"/>
 </domain>
diff --git a/cayenne-server/src/test/resources/generated.map.xml b/cayenne-server/src/test/resources/generated.map.xml
index a46b4a9..549203c 100644
--- a/cayenne-server/src/test/resources/generated.map.xml
+++ b/cayenne-server/src/test/resources/generated.map.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <data-map xmlns="http://cayenne.apache.org/schema/10/modelMap"
 	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	 xsi:schemaLocation="http://cayenne.apache.org/schema/10/modelMap http://cayenne.apache.org/schema/10/modelMap.xsd"
+	 xsi:schemaLocation="http://cayenne.apache.org/schema/10/modelMap https://cayenne.apache.org/schema/10/modelMap.xsd"
 	 project-version="10">
 	<property name="defaultPackage" value="org.apache.cayenne.testdo.generated"/>
 	<property name="defaultSuperclass" value="org.apache.cayenne.CayenneDataObject"/>
@@ -41,6 +41,11 @@
 		<db-attribute name="ID1" type="INTEGER"/>
 		<db-attribute name="ID2" type="INTEGER"/>
 	</db-entity>
+	<db-entity name="GENERATED_REFLEXIVE">
+		<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isGenerated="true" isMandatory="true"/>
+		<db-attribute name="NAME" type="VARCHAR" length="255"/>
+		<db-attribute name="REF_ID" type="INTEGER"/>
+	</db-entity>
 	<obj-entity name="GeneratedColumnCompKey" className="org.apache.cayenne.testdo.generated.GeneratedColumnCompKey" dbEntityName="GENERATED_COLUMN_COMP_KEY">
 		<obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
 	</obj-entity>
@@ -58,6 +63,9 @@
 	</obj-entity>
 	<obj-entity name="GeneratedF1" className="org.apache.cayenne.testdo.generated.GeneratedF1" clientClassName="test.client.GeneratedF1" dbEntityName="GENERATED_F1" superClassName="org.apache.cayenne.CayenneDataObject" clientSuperClassName="org.apache.cayenne.PersistentObject"/>
 	<obj-entity name="GeneratedF2" className="org.apache.cayenne.testdo.generated.GeneratedF2" clientClassName="test.client.GeneratedF2" dbEntityName="GENERATED_F2" superClassName="org.apache.cayenne.CayenneDataObject" clientSuperClassName="org.apache.cayenne.PersistentObject"/>
+	<obj-entity name="GeneratedReflexive" className="org.apache.cayenne.testdo.generated.GeneratedReflexive" clientClassName="test.client.GeneratedReflexive" dbEntityName="GENERATED_REFLEXIVE" superClassName="org.apache.cayenne.CayenneDataObject" clientSuperClassName="org.apache.cayenne.PersistentObject">
+		<obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
+	</obj-entity>
 	<db-relationship name="toMaster" source="GENERATED_COLUMN_COMP_KEY" target="GENERATED_COLUMN_COMP_M">
 		<db-attribute-pair source="PROPAGATED_PK" target="ID"/>
 	</db-relationship>
@@ -82,10 +90,14 @@
 	<db-relationship name="f2" source="GENERATED_JOIN" target="GENERATED_F2">
 		<db-attribute-pair source="ID2" target="ID"/>
 	</db-relationship>
+	<db-relationship name="next" source="GENERATED_REFLEXIVE" target="GENERATED_REFLEXIVE">
+		<db-attribute-pair source="REF_ID" target="ID"/>
+	</db-relationship>
 	<obj-relationship name="toMaster" source="GeneratedColumnCompKey" target="GeneratedColumnCompMaster" db-relationship-path="toMaster"/>
 	<obj-relationship name="toDetail" source="GeneratedColumnCompMaster" target="GeneratedColumnCompKey" db-relationship-path="toDetail"/>
 	<obj-relationship name="toMaster" source="GeneratedColumnDep" target="GeneratedColumnTestEntity" db-relationship-path="toMaster"/>
 	<obj-relationship name="toDep" source="GeneratedColumnTestEntity" target="GeneratedColumnDep" db-relationship-path="toDep"/>
 	<obj-relationship name="f2" source="GeneratedF1" target="GeneratedF2" deleteRule="Nullify" db-relationship-path="join.f2"/>
 	<obj-relationship name="f1" source="GeneratedF2" target="GeneratedF1" deleteRule="Nullify" db-relationship-path="join.f1"/>
+	<obj-relationship name="next" source="GeneratedReflexive" target="GeneratedReflexive" deleteRule="Nullify" db-relationship-path="next"/>
 </data-map>
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTabController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTabController.java
index 5fbd9c7..fa36ac0 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTabController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/domain/CgenTabController.java
@@ -63,6 +63,8 @@
                 if(cgenConfiguration == null) {
                     cgenConfiguration = createConfiguration(dataMap);
                 }
+                // should always run here
+                cgenConfiguration.setForce(true);
                 ClassGenerationAction classGenerationAction = new ToolsInjectorBuilder()
                         .addModule(binder
                                 -> binder.bind(DataChannelMetaData.class).toInstance(metaData))
diff --git a/pom.xml b/pom.xml
index b1cdeb9..059d832 100644
--- a/pom.xml
+++ b/pom.xml
@@ -811,6 +811,9 @@
 								org.apache.cayenne.build-tools:cayenne-legal:${project.version}
 							</resourceBundle>
 						</resourceBundles>
+						<properties>
+							<binary>false</binary>
+						</properties>
 					</configuration>
 				</plugin>
 				<plugin>