diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
index 3f9382dcf..27326437e 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
@@ -63,6 +63,8 @@ import org.apache.openjpa.util.ObjectId;
public class FieldMapping
extends FieldMetaData
implements ValueMapping, FieldStrategy {
+
+ private static final long serialVersionUID = 142185362294762433L;
private static final Localizer _loc = Localizer.forPackage
(FieldMapping.class);
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ValueMappingImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ValueMappingImpl.java
index db518e477..ae265db73 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ValueMappingImpl.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ValueMappingImpl.java
@@ -50,6 +50,8 @@ import org.apache.openjpa.util.MetaDataException;
public class ValueMappingImpl
extends ValueMetaDataImpl
implements ValueMapping {
+
+ private static final long serialVersionUID = 6440545965133775709L;
private static final Localizer _loc = Localizer.forPackage
(ValueMappingImpl.class);
diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
index c30b48f9b..1c0ce0558 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
@@ -78,6 +78,8 @@ public class FieldMetaData
extends Extensions
implements ValueMetaData, MetaDataContext, MetaDataModes, Commentable {
+ private static final long serialVersionUID = -566180883009883198L;
+
/**
* Constant specifying that no null-value was given.
*/
@@ -2190,6 +2192,10 @@ public class FieldMetaData
public void setCascadePersist(int persist) {
_val.setCascadePersist(persist);
}
+
+ public void setCascadePersist(int cascade, boolean checkPUDefault) {
+ _val.setCascadePersist(cascade, checkPUDefault);
+ }
public int getCascadeAttach() {
return _val.getCascadeAttach();
diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
index 48a633399..c6f17f5ac 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
@@ -126,5 +126,13 @@ public interface MetaDataDefaults
* @since 2.0.0
*/
public boolean isNonDefaultMappingAllowed(OpenJPAConfiguration conf);
+
+ /**
+ * Whether cascade-persist was declared in the persistence unit defaults.
+ * @return
+ */
+ public Boolean isDefaultCascadePersistEnabled();
+
+ public void setDefaultCascadePersistEnabled(Boolean bool);
}
diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
index 5a831bc2a..79a9976dd 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
@@ -161,6 +161,14 @@ public class NoneMetaDataFactory
public Class> getManagedClass(Class> c) {
return null;
}
+
+ public Boolean isDefaultCascadePersistEnabled() {
+ return false;
+ }
+
+ public void setDefaultCascadePersistEnabled(Boolean bool) {
+
+ }
public boolean isAbstractMappingUniDirectional(OpenJPAConfiguration conf) {
return false;
diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java
index a09233314..d071023b1 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java
@@ -203,6 +203,13 @@ public interface ValueMetaData
*/
public void setCascadePersist(int cascade);
+ /**
+ * Cascade behavior for persist operation.
+ *
+ * @see #getCascadePersist
+ */
+ public void setCascadePersist(int cascade, boolean checkPUDefault);
+
/**
* Cascade behavior for attach operation. Only applies to
* persistence-capable values. Options are:
diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java
index 71bc845ad..6a0980dcc 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java
@@ -30,6 +30,8 @@ import org.apache.openjpa.util.UserException;
*/
public class ValueMetaDataImpl
implements ValueMetaData {
+
+ private static final long serialVersionUID = 6766697443293395831L;
private static final Localizer _loc = Localizer.forPackage
(ValueMetaDataImpl.class);
@@ -58,6 +60,7 @@ public class ValueMetaDataImpl
private int _resMode = MODE_NONE;
private String _mappedBy = null;
private FieldMetaData _mappedByMeta = null;
+ private boolean _checkPUDefaultCascadePersist = true;
protected ValueMetaDataImpl(FieldMetaData owner) {
_owner = owner;
@@ -236,15 +239,52 @@ public class ValueMetaDataImpl
if (_owner.getManagement() != FieldMetaData.MANAGE_PERSISTENT)
return CASCADE_NONE;
if (isDeclaredTypePC())
- return _persist;
+ return checkPUDefaultCascadePersist();
if (!isTypePC())
return CASCADE_NONE;
// if only externalized type is pc, can't cascade immediate
- return (_persist == CASCADE_IMMEDIATE) ? CASCADE_AUTO : _persist;
+ return (_persist == CASCADE_IMMEDIATE) ? CASCADE_AUTO : checkPUDefaultCascadePersist();
+ }
+
+ /**
+ * Check if the persistence unit default has been enabled. If so, then change
+ * CASCADE_NONE to CASCADE_IMMEDIATE.
+ * @return
+ */
+ private int checkPUDefaultCascadePersist() {
+ if (_checkPUDefaultCascadePersist) {
+ // Apply default only to entity relationships
+ boolean applyDefaultCascadePersist = false;
+
+ switch (_owner.getAssociationType()) {
+ case FieldMetaData.ONE_TO_ONE:
+ case FieldMetaData.ONE_TO_MANY:
+ case FieldMetaData.MANY_TO_MANY:
+ case FieldMetaData.MANY_TO_ONE:
+ applyDefaultCascadePersist = true;
+ default:
+ }
+
+ if (applyDefaultCascadePersist) {
+ Boolean dcpe = getRepository().getMetaDataFactory().getDefaults().isDefaultCascadePersistEnabled();
+ if (dcpe != null && dcpe.equals(Boolean.TRUE) && _persist == CASCADE_NONE) {
+ _persist = CASCADE_IMMEDIATE;
+ }
+ }
+
+ _checkPUDefaultCascadePersist = false;
+ }
+
+ return _persist;
}
public void setCascadePersist(int persist) {
+ setCascadePersist(persist, true);
+ }
+
+ public void setCascadePersist(int persist, boolean checkPUDefault) {
_persist = persist;
+ _checkPUDefaultCascadePersist = checkPUDefault;
}
public int getCascadeAttach() {
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/AnEmbeddable.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/AnEmbeddable.java
new file mode 100644
index 000000000..4e2151206
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/AnEmbeddable.java
@@ -0,0 +1,47 @@
+/*
+ * 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
+ *
+ * http://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.openjpa.persistence.cascade.pudefault;
+
+import javax.persistence.Basic;
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class AnEmbeddable {
+ @Basic
+ private String eStrData;
+
+ public AnEmbeddable() {
+
+ }
+
+ public String geteStrData() {
+ return eStrData;
+ }
+
+ public void seteStrData(String eStrData) {
+ this.eStrData = eStrData;
+ }
+
+ @Override
+ public String toString() {
+ return "AnEmbeddable [eStrData=" + eStrData + "]";
+ }
+
+
+}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/EmbeddableWithRelationships.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/EmbeddableWithRelationships.java
new file mode 100644
index 000000000..cf8b742ef
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/EmbeddableWithRelationships.java
@@ -0,0 +1,88 @@
+/*
+ * 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
+ *
+ * http://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.openjpa.persistence.cascade.pudefault;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.persistence.Embeddable;
+import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+
+@Embeddable
+public class EmbeddableWithRelationships {
+ @ManyToMany
+ private Collection colM2M;
+
+ @OneToMany
+ private Collection colO2M;
+
+ @ManyToOne
+ private PUDEntityB m2o;
+
+ @OneToOne
+ private PUDEntityB o2o;
+
+ public EmbeddableWithRelationships() {
+ colM2M = new ArrayList();
+ colO2M = new ArrayList();
+ }
+
+ public Collection getColM2M() {
+ return colM2M;
+ }
+
+ public void setColM2M(Collection colM2M) {
+ this.colM2M = colM2M;
+ }
+
+ public Collection getColO2M() {
+ return colO2M;
+ }
+
+ public void setColO2M(Collection colO2M) {
+ this.colO2M = colO2M;
+ }
+
+ public PUDEntityB getM2o() {
+ return m2o;
+ }
+
+ public void setM2o(PUDEntityB m2o) {
+ this.m2o = m2o;
+ }
+
+ public PUDEntityB getO2o() {
+ return o2o;
+ }
+
+ public void setO2o(PUDEntityB o2o) {
+ this.o2o = o2o;
+ }
+
+ @Override
+ public String toString() {
+ return "EmbeddableWithRelationships [colM2M=" + colM2M + ", colO2M="
+ + colO2M + ", m2o=" + m2o + ", o2o=" + o2o + "]";
+ }
+
+
+}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/PUDEntityA01.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/PUDEntityA01.java
new file mode 100644
index 000000000..d37c768a4
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/PUDEntityA01.java
@@ -0,0 +1,116 @@
+/*
+ * 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
+ *
+ * http://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.openjpa.persistence.cascade.pudefault;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+
+@Entity
+public class PUDEntityA01 {
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private int id;
+
+ @Basic
+ private String strData;
+
+ @ManyToMany
+ private Collection colM2M;
+
+ @OneToMany
+ private Collection colO2M;
+
+ @ManyToOne
+ private PUDEntityB m2o;
+
+ @OneToOne
+ private PUDEntityB o2o;
+
+ public PUDEntityA01() {
+ colM2M = new ArrayList();
+ colO2M = new ArrayList();
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getStrData() {
+ return strData;
+ }
+
+ public void setStrData(String strData) {
+ this.strData = strData;
+ }
+
+ public Collection getColM2M() {
+ return colM2M;
+ }
+
+ public void setColM2M(Collection colM2M) {
+ this.colM2M = colM2M;
+ }
+
+ public Collection getColO2M() {
+ return colO2M;
+ }
+
+ public void setColO2M(Collection colO2M) {
+ this.colO2M = colO2M;
+ }
+
+ public PUDEntityB getM2o() {
+ return m2o;
+ }
+
+ public void setM2o(PUDEntityB m2o) {
+ this.m2o = m2o;
+ }
+
+ public PUDEntityB getO2o() {
+ return o2o;
+ }
+
+ public void setO2o(PUDEntityB o2o) {
+ this.o2o = o2o;
+ }
+
+ @Override
+ public String toString() {
+ return "PUDEntityA01 [id=" + id + ", strData=" + strData + ", colM2M="
+ + colM2M + ", colO2M=" + colO2M + ", m2o=" + m2o + ", o2o=" + o2o
+ + "]";
+ }
+
+
+}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/PUDEntityA02.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/PUDEntityA02.java
new file mode 100644
index 000000000..b0f070b2d
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/PUDEntityA02.java
@@ -0,0 +1,75 @@
+/*
+ * 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
+ *
+ * http://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.openjpa.persistence.cascade.pudefault;
+
+import javax.persistence.Basic;
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+@Entity
+public class PUDEntityA02 {
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private int id;
+
+ @Basic
+ private String strData;
+
+ @Embedded
+ private EmbeddableWithRelationships emb;
+
+ public PUDEntityA02() {
+ emb = new EmbeddableWithRelationships();
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getStrData() {
+ return strData;
+ }
+
+ public void setStrData(String strData) {
+ this.strData = strData;
+ }
+
+ public EmbeddableWithRelationships getEmb() {
+ return emb;
+ }
+
+ public void setEmb(EmbeddableWithRelationships emb) {
+ this.emb = emb;
+ }
+
+ @Override
+ public String toString() {
+ return "PUDEntityA02 [id=" + id + ", strData=" + strData + ", emb="
+ + emb + "]";
+ }
+
+
+}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/PUDEntityAE01.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/PUDEntityAE01.java
new file mode 100644
index 000000000..01ea13467
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/PUDEntityAE01.java
@@ -0,0 +1,128 @@
+/*
+ * 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
+ *
+ * http://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.openjpa.persistence.cascade.pudefault;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.persistence.Basic;
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+
+@Entity
+public class PUDEntityAE01 {
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private int id;
+
+ @Basic
+ private String strData;
+
+ @ManyToMany
+ private Collection colM2M;
+
+ @OneToMany
+ private Collection colO2M;
+
+ @ManyToOne
+ private PUDEntityB m2o;
+
+ @OneToOne
+ private PUDEntityB o2o;
+
+ @Embedded
+ private AnEmbeddable ane;
+
+ public PUDEntityAE01() {
+ colM2M = new ArrayList();
+ colO2M = new ArrayList();
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getStrData() {
+ return strData;
+ }
+
+ public void setStrData(String strData) {
+ this.strData = strData;
+ }
+
+ public Collection getColM2M() {
+ return colM2M;
+ }
+
+ public void setColM2M(Collection colM2M) {
+ this.colM2M = colM2M;
+ }
+
+ public Collection getColO2M() {
+ return colO2M;
+ }
+
+ public void setColO2M(Collection colO2M) {
+ this.colO2M = colO2M;
+ }
+
+ public PUDEntityB getM2o() {
+ return m2o;
+ }
+
+ public void setM2o(PUDEntityB m2o) {
+ this.m2o = m2o;
+ }
+
+ public PUDEntityB getO2o() {
+ return o2o;
+ }
+
+ public void setO2o(PUDEntityB o2o) {
+ this.o2o = o2o;
+ }
+
+ public AnEmbeddable getAne() {
+ return ane;
+ }
+
+ public void setAne(AnEmbeddable ane) {
+ this.ane = ane;
+ }
+
+ @Override
+ public String toString() {
+ return "PUDEntityAE01 [id=" + id + ", strData=" + strData + ", colM2M="
+ + colM2M + ", colO2M=" + colO2M + ", m2o=" + m2o + ", o2o=" + o2o
+ + ", ane=" + ane + "]";
+ }
+
+
+}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/PUDEntityB.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/PUDEntityB.java
new file mode 100644
index 000000000..ffec718ac
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/PUDEntityB.java
@@ -0,0 +1,62 @@
+/*
+ * 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
+ *
+ * http://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.openjpa.persistence.cascade.pudefault;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+@Entity
+public class PUDEntityB {
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private int id;
+
+ @Basic
+ private String strData;
+
+ public PUDEntityB() {
+
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getStrData() {
+ return strData;
+ }
+
+ public void setStrData(String strData) {
+ this.strData = strData;
+ }
+
+ @Override
+ public String toString() {
+ return "PUDEntityB [id=" + id + ", strData=" + strData + "]";
+ }
+
+
+}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/TestNoPUDefaultCascadePersist.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/TestNoPUDefaultCascadePersist.java
new file mode 100644
index 000000000..b4b130630
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/TestNoPUDefaultCascadePersist.java
@@ -0,0 +1,271 @@
+/*
+ * 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
+ *
+ * http://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.openjpa.persistence.cascade.pudefault;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestNoPUDefaultCascadePersist extends SingleEMFTestCase {
+ public void setUp() throws Exception {
+ super.setUp(PUDEntityA01.class, PUDEntityAE01.class, PUDEntityB.class, AnEmbeddable.class,
+ CLEAR_TABLES);
+ }
+
+
+ public void testPUDefaultCascadePersistOverM2M() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityA01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityA01();
+ entity.setStrData("PUDEntityA01");
+
+ for (int i = 0; i < 10; i++) {
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.getColM2M().add(b);
+ }
+
+ em.persist(entity);
+ try {
+ em.getTransaction().commit();
+ fail("No Exception thrown.");
+ } catch (Exception e) {
+ // Expected
+ }
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverO2M() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityA01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityA01();
+ entity.setStrData("PUDEntityA01");
+
+ for (int i = 0; i < 10; i++) {
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.getColO2M().add(b);
+ }
+
+ em.persist(entity);
+ try {
+ em.getTransaction().commit();
+ fail("No Exception thrown.");
+ } catch (Exception e) {
+ // Expected
+ }
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverO2O() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityA01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityA01();
+ entity.setStrData("PUDEntityA01");
+
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.setO2o(b);
+
+ em.persist(entity);
+ try {
+ em.getTransaction().commit();
+ fail("No Exception thrown.");
+ } catch (Exception e) {
+ // Expected
+ }
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverM2O() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityA01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityA01();
+ entity.setStrData("PUDEntityA01");
+
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.setM2o(b);
+
+ em.persist(entity);
+ try {
+ em.getTransaction().commit();
+ fail("No Exception thrown.");
+ } catch (Exception e) {
+ // Expected
+ }
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverM2MWithEmbed() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityAE01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityAE01();
+ entity.setStrData("PUDEntityAE01");
+
+ for (int i = 0; i < 10; i++) {
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.getColM2M().add(b);
+ }
+
+ em.persist(entity);
+ try {
+ em.getTransaction().commit();
+ fail("No Exception thrown.");
+ } catch (Exception e) {
+ // Expected
+ }
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverO2MWithEmbed() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityAE01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityAE01();
+ entity.setStrData("PUDEntityAE01");
+
+ for (int i = 0; i < 10; i++) {
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.getColO2M().add(b);
+ }
+
+ em.persist(entity);
+ try {
+ em.getTransaction().commit();
+ fail("No Exception thrown.");
+ } catch (Exception e) {
+ // Expected
+ }
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverO2OWithEmbed() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityAE01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityAE01();
+ entity.setStrData("PUDEntityAE01");
+
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.setO2o(b);
+
+ em.persist(entity);
+ try {
+ em.getTransaction().commit();
+ fail("No Exception thrown.");
+ } catch (Exception e) {
+ // Expected
+ }
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverM2OWithEmbed() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityAE01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityAE01();
+ entity.setStrData("PUDEntityAE01");
+
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.setM2o(b);
+
+ em.persist(entity);
+ try {
+ em.getTransaction().commit();
+ fail("No Exception thrown.");
+ } catch (Exception e) {
+ // Expected
+ }
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/TestPUDefaultCascadePersist.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/TestPUDefaultCascadePersist.java
new file mode 100644
index 000000000..f099283fa
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/pudefault/TestPUDefaultCascadePersist.java
@@ -0,0 +1,504 @@
+/*
+ * 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
+ *
+ * http://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.openjpa.persistence.cascade.pudefault;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestPUDefaultCascadePersist extends SingleEMFTestCase {
+ private EntityManagerFactory emf = null;
+ public void setUp() throws Exception {
+ super.setUp();
+ emf = OpenJPAPersistence.
+ createEntityManagerFactory("TestPUDefaultCascadePersist",
+ "org/apache/openjpa/persistence/cascade/pudefault/META-INF/persistence.xml");
+// super.setUp(PUDEntityA01.class, PUDEntityB.class,
+// "org/apache/openjpa/persistence/cascade/pudefault/META-INF/cascadepersistorm.xml",
+// CLEAR_TABLES);
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ emf.close();
+ }
+
+ public void testPUDefaultCascadePersistOverM2M() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityA01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityA01();
+ entity.setStrData("PUDEntityA01");
+
+ for (int i = 0; i < 10; i++) {
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.getColM2M().add(b);
+ }
+
+ em.persist(entity);
+ em.getTransaction().commit();
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+
+ em.close();
+ em = emf.createEntityManager();
+
+ try {
+ PUDEntityA01 f_entity = em.find(PUDEntityA01.class, entity.getId());
+ assertNotNull(f_entity);
+ assertNotSame(entity, f_entity);
+ assertEquals(10, f_entity.getColM2M().size());
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverO2M() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityA01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityA01();
+ entity.setStrData("PUDEntityA01");
+
+ for (int i = 0; i < 10; i++) {
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.getColO2M().add(b);
+ }
+
+ em.persist(entity);
+ em.getTransaction().commit();
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+
+ em.close();
+ em = emf.createEntityManager();
+
+ try {
+ PUDEntityA01 f_entity = em.find(PUDEntityA01.class, entity.getId());
+ assertNotNull(f_entity);
+ assertNotSame(entity, f_entity);
+ assertEquals(10, f_entity.getColO2M().size());
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverO2O() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityA01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityA01();
+ entity.setStrData("PUDEntityA01");
+
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.setO2o(b);
+
+ em.persist(entity);
+ em.getTransaction().commit();
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+
+ em.close();
+ em = emf.createEntityManager();
+
+ try {
+ PUDEntityA01 f_entity = em.find(PUDEntityA01.class, entity.getId());
+ assertNotNull(f_entity);
+ assertNotSame(entity, f_entity);
+ assertNotNull(entity.getO2o());
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverM2O() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityA01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityA01();
+ entity.setStrData("PUDEntityA01");
+
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.setM2o(b);
+
+ em.persist(entity);
+ em.getTransaction().commit();
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+
+ em.close();
+ em = emf.createEntityManager();
+
+ try {
+ PUDEntityA01 f_entity = em.find(PUDEntityA01.class, entity.getId());
+ assertNotNull(f_entity);
+ assertNotSame(entity, f_entity);
+ assertNotNull(entity.getM2o());
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+ }
+
+
+
+ public void testPUDefaultCascadePersistOverM2MWithEmbed() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityAE01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityAE01();
+ entity.setStrData("PUDEntityAE01");
+
+ for (int i = 0; i < 10; i++) {
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.getColM2M().add(b);
+ }
+
+ em.persist(entity);
+ em.getTransaction().commit();
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+
+ em.close();
+ em = emf.createEntityManager();
+
+ try {
+ PUDEntityAE01 f_entity = em.find(PUDEntityAE01.class, entity.getId());
+ assertNotNull(f_entity);
+ assertNotSame(entity, f_entity);
+ assertEquals(10, f_entity.getColM2M().size());
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverO2MWithEmbed() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityAE01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityAE01();
+ entity.setStrData("PUDEntityAE01");
+
+ for (int i = 0; i < 10; i++) {
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.getColO2M().add(b);
+ }
+
+ em.persist(entity);
+ em.getTransaction().commit();
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+
+ em.close();
+ em = emf.createEntityManager();
+
+ try {
+ PUDEntityAE01 f_entity = em.find(PUDEntityAE01.class, entity.getId());
+ assertNotNull(f_entity);
+ assertNotSame(entity, f_entity);
+ assertEquals(10, f_entity.getColO2M().size());
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverO2OWithEmbed() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityAE01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityAE01();
+ entity.setStrData("PUDEntityAE01");
+
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.setO2o(b);
+
+ em.persist(entity);
+ em.getTransaction().commit();
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+
+ em.close();
+ em = emf.createEntityManager();
+
+ try {
+ PUDEntityAE01 f_entity = em.find(PUDEntityAE01.class, entity.getId());
+ assertNotNull(f_entity);
+ assertNotSame(entity, f_entity);
+ assertNotNull(entity.getO2o());
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverM2OWithEmbed() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityAE01 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityAE01();
+ entity.setStrData("PUDEntityAE01");
+
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.setM2o(b);
+
+ em.persist(entity);
+ em.getTransaction().commit();
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+
+ em.close();
+ em = emf.createEntityManager();
+
+ try {
+ PUDEntityAE01 f_entity = em.find(PUDEntityAE01.class, entity.getId());
+ assertNotNull(f_entity);
+ assertNotSame(entity, f_entity);
+ assertNotNull(entity.getM2o());
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+ }
+
+
+ public void testPUDefaultCascadePersistOverM2MEmbbedRel() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityA02 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityA02();
+ entity.setStrData("PUDEntityA02");
+
+ for (int i = 0; i < 10; i++) {
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.getEmb().getColM2M().add(b);
+ }
+
+ em.persist(entity);
+ em.getTransaction().commit();
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+
+ em.close();
+ em = emf.createEntityManager();
+
+ try {
+ PUDEntityA02 f_entity = em.find(PUDEntityA02.class, entity.getId());
+ assertNotNull(f_entity);
+ assertNotSame(entity, f_entity);
+ assertEquals(10, f_entity.getEmb().getColM2M().size());
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverO2MEmbbedRel() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityA02 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityA02();
+ entity.setStrData("PUDEntityA02");
+
+ for (int i = 0; i < 10; i++) {
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.getEmb().getColO2M().add(b);
+ }
+
+ em.persist(entity);
+ em.getTransaction().commit();
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+
+ em.close();
+ em = emf.createEntityManager();
+
+ try {
+ PUDEntityA02 f_entity = em.find(PUDEntityA02.class, entity.getId());
+ assertNotNull(f_entity);
+ assertNotSame(entity, f_entity);
+ assertEquals(10, f_entity.getEmb().getColO2M().size());
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverO2OEmbbedRel() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityA02 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityA02();
+ entity.setStrData("PUDEntityA02");
+
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.getEmb().setO2o(b);
+
+ em.persist(entity);
+ em.getTransaction().commit();
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+
+ em.close();
+ em = emf.createEntityManager();
+
+ try {
+ PUDEntityA02 f_entity = em.find(PUDEntityA02.class, entity.getId());
+ assertNotNull(f_entity);
+ assertNotSame(entity, f_entity);
+ assertNotNull(entity.getEmb().getO2o());
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+ }
+
+ public void testPUDefaultCascadePersistOverM2OEmbbedRel() {
+ EntityManager em = emf.createEntityManager();
+
+ PUDEntityA02 entity = null;
+ try {
+ em.getTransaction().begin();
+
+ entity = new PUDEntityA02();
+ entity.setStrData("PUDEntityA02");
+
+ PUDEntityB b = new PUDEntityB();
+ b.setStrData("B");
+ entity.getEmb().setM2o(b);
+
+ em.persist(entity);
+ em.getTransaction().commit();
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+
+ em.close();
+ em = emf.createEntityManager();
+
+ try {
+ PUDEntityA02 f_entity = em.find(PUDEntityA02.class, entity.getId());
+ assertNotNull(f_entity);
+ assertNotSame(entity, f_entity);
+ assertNotNull(entity.getEmb().getM2o());
+ } finally {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ }
+ }
+
+
+}
diff --git a/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/cascade/pudefault/META-INF/cascadepersistorm.xml b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/cascade/pudefault/META-INF/cascadepersistorm.xml
new file mode 100644
index 000000000..b93780b49
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/cascade/pudefault/META-INF/cascadepersistorm.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/cascade/pudefault/META-INF/persistence.xml b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/cascade/pudefault/META-INF/persistence.xml
new file mode 100644
index 000000000..ae1b9fc24
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/cascade/pudefault/META-INF/persistence.xml
@@ -0,0 +1,38 @@
+
+
+
+
+ org/apache/openjpa/persistence/cascade/pudefault/META-INF/cascadepersistorm.xml
+ org.apache.openjpa.persistence.cascade.pudefault.PUDEntityA01
+ org.apache.openjpa.persistence.cascade.pudefault.PUDEntityAE01
+ org.apache.openjpa.persistence.cascade.pudefault.PUDEntityA02
+ org.apache.openjpa.persistence.cascade.pudefault.PUDEntityB
+ org.apache.openjpa.persistence.cascade.pudefault.AnEmbeddable
+ org.apache.openjpa.persistence.cascade.pudefault.EmbeddableWithRelationships
+
+
+
+
+
+
diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
index ce5b478f9..0b0ed3046 100644
--- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
+++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
@@ -1770,7 +1770,7 @@ public class AnnotationPersistenceMetaDataParser
if (cascade == CascadeType.ALL || cascade == CascadeType.REMOVE)
vmd.setCascadeDelete(ValueMetaData.CASCADE_IMMEDIATE);
if (cascade == CascadeType.ALL || cascade == CascadeType.PERSIST)
- vmd.setCascadePersist(ValueMetaData.CASCADE_IMMEDIATE);
+ vmd.setCascadePersist(ValueMetaData.CASCADE_IMMEDIATE, false);
if (cascade == CascadeType.ALL || cascade == CascadeType.MERGE)
vmd.setCascadeAttach(ValueMetaData.CASCADE_IMMEDIATE);
if (cascade == CascadeType.ALL || cascade == CascadeType.DETACH)
diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
index ffc00dc24..e21094ec6 100644
--- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
+++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
@@ -133,6 +133,7 @@ public class PersistenceMetaDataDefaults
protected SetterFilter setterFilter = new SetterFilter();
private Boolean _isAbstractMappingUniDirectional = null;
private Boolean _isNonDefaultMappingAllowed = null;
+ private Boolean _isCascadePersistPersistenceUnitDefaultEnabled = null;
public PersistenceMetaDataDefaults() {
setCallbackMode(CALLBACK_RETHROW | CALLBACK_ROLLBACK |
@@ -945,4 +946,13 @@ public class PersistenceMetaDataDefaults
_isNonDefaultMappingAllowed = conf.getCompatibilityInstance().
isNonDefaultMappingAllowed();
}
+
+ public Boolean isDefaultCascadePersistEnabled() {
+ return _isCascadePersistPersistenceUnitDefaultEnabled;
+ }
+
+ public void setDefaultCascadePersistEnabled(Boolean bool) {
+ _isCascadePersistPersistenceUnitDefaultEnabled = bool;
+ }
+
}
diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
index 84974c807..bb94503a2 100644
--- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
+++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
@@ -63,6 +63,7 @@ import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.meta.LifecycleMetaData;
import org.apache.openjpa.meta.MetaDataContext;
+import org.apache.openjpa.meta.MetaDataDefaults;
import org.apache.openjpa.meta.MetaDataFactory;
import org.apache.openjpa.meta.UpdateStrategies;
@@ -1329,6 +1330,8 @@ public class XMLPersistenceMetaDataParser
throws SAXException {
if (!isMetaDataMode())
return false;
+
+ boolean puDefault = false;
Set cascades = null;
if (currentElement() instanceof FieldMetaData) {
@@ -1339,10 +1342,17 @@ public class XMLPersistenceMetaDataParser
if (_pkgCascades == null)
_pkgCascades = EnumSet.noneOf(CascadeType.class);
cascades = _pkgCascades;
+ puDefault = true;
}
boolean all = ELEM_CASCADE_ALL == tag;
- if (all || ELEM_CASCADE_PER == tag)
+ if (all || ELEM_CASCADE_PER == tag) {
cascades.add(PERSIST);
+ if (puDefault) {
+ MetaDataDefaults mdd = _repos.getMetaDataFactory().getDefaults();
+ mdd.setDefaultCascadePersistEnabled(true);
+ }
+ }
+
if (all || ELEM_CASCADE_REM == tag)
cascades.add(REMOVE);
if (all || ELEM_CASCADE_MER == tag)
@@ -1371,7 +1381,7 @@ public class XMLPersistenceMetaDataParser
for (CascadeType cascade : cascades) {
switch (cascade) {
case PERSIST:
- vmd.setCascadePersist(ValueMetaData.CASCADE_IMMEDIATE);
+ vmd.setCascadePersist(ValueMetaData.CASCADE_IMMEDIATE, false);
break;
case MERGE:
vmd.setCascadeAttach(ValueMetaData.CASCADE_IMMEDIATE);