You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by fa...@apache.org on 2009/02/04 17:31:54 UTC

svn commit: r740781 - in /openjpa/trunk: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ openjpa-persistence-jdbc/src/test/resources/META-INF/ openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed...

Author: faywang
Date: Wed Feb  4 16:31:54 2009
New Revision: 740781

URL: http://svn.apache.org/viewvc?rev=740781&view=rev
Log:
OPENJPA-870: orm support for OrphanRemoval

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/CustomerXml.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/OrderXml.java
Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ContactInfo.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/JobInfo.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/LocationDetails.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ParkingSpot.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/PhoneNumber.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ProgramManager.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddableXml.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ContactInfo.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ContactInfo.java?rev=740781&r1=740780&r2=740781&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ContactInfo.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ContactInfo.java Wed Feb  4 16:31:54 2009
@@ -1,3 +1,21 @@
+/*
+ * 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.embed;
 
 import javax.persistence.*;

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/CustomerXml.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/CustomerXml.java?rev=740781&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/CustomerXml.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/CustomerXml.java Wed Feb  4 16:31:54 2009
@@ -0,0 +1,84 @@
+/*
+ * 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.embed;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class CustomerXml {
+    protected int id;
+    
+    protected String name;
+    
+    protected Set<OrderXml> orders = new HashSet<OrderXml>();
+    
+    public int getId() {
+        return id;
+    }
+    
+    public void setId(int id) {
+        this.id = id;
+    }
+    
+    public String getName() {
+        return name;
+    }
+    
+    public void setName(String name) {
+        this.name = name;
+    }
+    
+    public Set<OrderXml> getOrders() {
+        return orders;
+    }
+
+    public void setOrders(Set<OrderXml> orders) {
+        this.orders = orders;
+    }
+    
+    public void addOrder(OrderXml order) {
+        orders.add(order);
+    }
+    
+    public boolean equals(Object obj) {
+        CustomerXml c0 = (CustomerXml) obj;
+        if (c0 == null) return false;
+        if (c0.getId() != id) return false;
+        if (!c0.getName().equals(name)) return false;
+        Set<OrderXml> orders0 = c0.getOrders();
+        if (orders0.size() != orders.size())
+            return false;
+        for (OrderXml o : orders) {
+            if (!contains(orders0, o))
+                return false;
+        }
+        return true;
+    }
+    
+    private boolean contains(Set<OrderXml> orders0, OrderXml o) {
+        int id = o.getId();
+        for (OrderXml o0 : orders0) {
+            if (o0.getId() == id)
+                return true;
+        }
+        return false;
+    }
+}
+
+

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/JobInfo.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/JobInfo.java?rev=740781&r1=740780&r2=740781&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/JobInfo.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/JobInfo.java Wed Feb  4 16:31:54 2009
@@ -1,7 +1,24 @@
+/*
+ * 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.embed;
 
 import javax.persistence.*;
-import java.util.*;
 
 @Embeddable
 public class JobInfo {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/LocationDetails.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/LocationDetails.java?rev=740781&r1=740780&r2=740781&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/LocationDetails.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/LocationDetails.java Wed Feb  4 16:31:54 2009
@@ -1,3 +1,21 @@
+/*
+ * 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.embed;
 
 import javax.persistence.*;

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/OrderXml.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/OrderXml.java?rev=740781&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/OrderXml.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/OrderXml.java Wed Feb  4 16:31:54 2009
@@ -0,0 +1,61 @@
+/*
+ * 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.embed;
+
+
+public class OrderXml {
+    protected int id;
+    
+    protected String description;
+    
+    protected CustomerXml cust;
+    
+    public CustomerXml getCust() {
+        return cust;
+    }
+    
+    public void setCust(CustomerXml cust) {
+        this.cust = cust;
+    }
+    
+    public int getId() {
+        return id;
+    }
+    
+    public void setId(int id) {
+        this.id = id;
+    }
+    
+    public String getDescription() {
+        return description;
+    }
+    
+    public void setDescription(String desc) {
+        this.description = desc;
+    }
+    
+    public boolean equals(Object obj) {
+        OrderXml o0 = (OrderXml) obj;
+        if (o0 == null) return false;
+        if (o0.getId() != id) return false;
+        if (!o0.getDescription().equals(description)) return false;
+        if (!o0.getCust().equals(cust)) return false;
+        return true;
+    }
+}

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ParkingSpot.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ParkingSpot.java?rev=740781&r1=740780&r2=740781&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ParkingSpot.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ParkingSpot.java Wed Feb  4 16:31:54 2009
@@ -1,3 +1,21 @@
+/*
+ * 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.embed;
 
 import javax.persistence.*;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/PhoneNumber.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/PhoneNumber.java?rev=740781&r1=740780&r2=740781&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/PhoneNumber.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/PhoneNumber.java Wed Feb  4 16:31:54 2009
@@ -1,3 +1,21 @@
+/*
+ * 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.embed;
 
 import javax.persistence.*;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ProgramManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ProgramManager.java?rev=740781&r1=740780&r2=740781&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ProgramManager.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ProgramManager.java Wed Feb  4 16:31:54 2009
@@ -1,3 +1,21 @@
+/*
+ * 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.embed;
 
 import javax.persistence.*;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddableXml.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddableXml.java?rev=740781&r1=740780&r2=740781&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddableXml.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddableXml.java Wed Feb  4 16:31:54 2009
@@ -44,12 +44,16 @@
     public int newVpId = 100;
     public int numItems = 2;
     public int itemId = 1;
+    public int cId = 1;
+    public int oId = 1;
 
     public int numImagesPerItem = 3;
     public int numDepartments = 2;
     public int numEmployeesPerDept = 2;
     public int numCompany = 2;
     public int numDivisionsPerCo = 2;
+    public int numCustomers = 1;
+    public int numOrdersPerCustomer = 2;
     
     public void setUp() {
         setUp(CLEAR_TABLES);
@@ -625,5 +629,107 @@
     public void assertVicePresident(VicePresidentXml vp) {
         int id = vp.getId();
         String name = vp.getName();
-    } 
+    }
+    
+    public void createOrphanRemoval() {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        for (int i = 0; i < numCustomers; i++)
+            createCustomer(em, cId++);
+        tran.begin();
+        em.flush();
+        tran.commit();
+        em.close();
+    }
+
+    public CustomerXml createCustomer(EntityManager em, int id) {
+        CustomerXml c = new CustomerXml();
+        c.setId(id);
+        c.setName("name" + id);
+        for (int i = 0; i < numOrdersPerCustomer; i++) {
+            OrderXml order = createOrder(em, oId++);
+            c.addOrder(order);
+            order.setCust(c);
+            em.persist(order);
+        }
+        em.persist(c);
+        return c;
+    }
+
+    public OrderXml createOrder(EntityManager em, int id) {
+        OrderXml o = new OrderXml();
+        o.setId(id);
+        em.persist(o);
+        return o;
+    }
+    
+    public void testOrphanRemovalTarget() {
+        createOrphanRemoval();
+        EntityManager em = emf.createEntityManager();
+        int count = count(OrderXml.class);
+        assertEquals(numOrdersPerCustomer * numCustomers, count);
+
+        CustomerXml c = em.find(CustomerXml.class, 1);
+        Set<OrderXml> orders = c.getOrders();
+        assertEquals(numOrdersPerCustomer, orders.size());
+
+        // OrphanRemoval: remove target: the order will be deleted from db
+        for (OrderXml order : orders) {
+            orders.remove(order);
+            break;
+        }
+        em.getTransaction().begin();
+        em.persist(c);
+        em.flush();
+        em.getTransaction().commit();
+        em.clear();
+
+        c = em.find(CustomerXml.class, 1);
+        orders = c.getOrders();
+        assertEquals(numOrdersPerCustomer - 1, orders.size());
+        count = count(OrderXml.class);
+        assertEquals(numOrdersPerCustomer * numCustomers - 1, count);
+        em.close();
+    }
+    
+    public void testOrphanRemovalTargetSetNull() {
+        createOrphanRemoval();
+        EntityManager em = emf.createEntityManager();
+        CustomerXml c = em.find(CustomerXml.class, 1);
+        System.err.println("C name = " + c.getName());
+        System.err.println("size before = " + c.getOrders().size());
+        c.setOrders(null);
+        em.getTransaction().begin();
+        em.persist(c);
+        em.flush();
+        em.getTransaction().commit();
+        em.clear();
+
+        int count = count(OrderXml.class);
+        assertEquals(numOrdersPerCustomer * (numCustomers - 1), count);
+        
+        c = em.find(CustomerXml.class, 1);
+        Set<OrderXml> orders = c.getOrders();
+        if (orders != null)
+            assertEquals(0, orders.size());
+        em.close();
+    }
+    
+    public void testOrphanRemovalSource() {
+        createOrphanRemoval();
+        EntityManager em = emf.createEntityManager();
+        
+        // OrphanRemoval: remove source
+        CustomerXml c = em.find(CustomerXml.class, 1);
+        em.getTransaction().begin();
+        em.remove(c);
+        em.flush();
+        em.getTransaction().commit();
+        em.clear();
+        
+        int count = count(OrderXml.class);
+        assertEquals(numOrdersPerCustomer * (numCustomers - 1), count);
+        
+        em.close();
+    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml?rev=740781&r1=740780&r2=740781&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml Wed Feb  4 16:31:54 2009
@@ -39,6 +39,7 @@
             class.
         </description>
         <mapping-file>org/apache/openjpa/persistence/xml/orm.xml</mapping-file>
+        <mapping-file>org/apache/openjpa/persistence/embed/embed-orm.xml</mapping-file>
         <properties>
             <property name="openjpa.jdbc.SynchronizeMappings"
                 value="buildSchema(ForeignKeys=true)"/>
@@ -107,6 +108,8 @@
         <class>org.apache.openjpa.persistence.embed.EntityA_Coll_Embed_EmbedXml</class>
         <class>org.apache.openjpa.persistence.embed.Embed_EmbedXml</class>
         <class>org.apache.openjpa.persistence.embed.EmbedXml</class>
+        <class>org.apache.openjpa.persistence.embed.CustomerXml</class>
+        <class>org.apache.openjpa.persistence.embed.OrderXml</class>
         <properties>
             <property name="openjpa.jdbc.SynchronizeMappings"
                   value="buildSchema(ForeignKeys=true)"/>

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml?rev=740781&r1=740780&r2=740781&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml Wed Feb  4 16:31:54 2009
@@ -123,40 +123,60 @@
 			</one-to-many>
 		</attributes>
 	</entity>
- 
-    <embeddable class="org.apache.openjpa.persistence.embed.Embed_EmbedXml" 
-                access="FIELD">
-        <attributes>
-            <basic name="intVal1">
-            </basic>
-            <basic name="intVal2">
-            </basic>
-            <basic name="intVal3">
-            </basic>
-            <embedded name="embed">
-                 <attribute-override name="intVal1">
-                   <column name="embed_intVal1"/>
-                 </attribute-override>
-                 <attribute-override name="intVal2">
-                   <column name="embed_intVal2"/>
-                 </attribute-override>
-                 <attribute-override name="intVal3">
-                   <column name="embed_intVal3"/>
-                 </attribute-override>
-            </embedded>
-        </attributes>
-    </embeddable>
 
-    <embeddable class="org.apache.openjpa.persistence.embed.EmbedXml" 
-                access="FIELD">
-        <attributes>
-            <basic name="intVal1">
-            </basic>
-            <basic name="intVal2">
-            </basic>
-            <basic name="intVal3">
-            </basic>
-        </attributes>
-    </embeddable>
-    
+	<entity name="CustomerXml"
+		class="org.apache.openjpa.persistence.embed.CustomerXml"
+		access="FIELD">
+		<table name="Customer_XML" />
+		<attributes>
+			<id name="id"></id>
+			<basic name="name" />
+			<one-to-many name="orders" mapped-by="cust"
+				orphan-removal="true" />
+		</attributes>
+	</entity>
+
+	<entity name="OrderXml"
+		class="org.apache.openjpa.persistence.embed.OrderXml"
+		access="FIELD">
+		<table name="Order_XML" />
+		<attributes>
+			<id name="id"></id>
+			<basic name="description" />
+			<many-to-one name="cust">
+				<join-column name="CUST_ID" nullable="false" />
+			</many-to-one>
+		</attributes>
+	</entity>
+
+	<embeddable
+		class="org.apache.openjpa.persistence.embed.Embed_EmbedXml"
+		access="FIELD">
+		<attributes>
+			<basic name="intVal1"></basic>
+			<basic name="intVal2"></basic>
+			<basic name="intVal3"></basic>
+			<embedded name="embed">
+				<attribute-override name="intVal1">
+					<column name="embed_intVal1" />
+				</attribute-override>
+				<attribute-override name="intVal2">
+					<column name="embed_intVal2" />
+				</attribute-override>
+				<attribute-override name="intVal3">
+					<column name="embed_intVal3" />
+				</attribute-override>
+			</embedded>
+		</attributes>
+	</embeddable>
+
+	<embeddable class="org.apache.openjpa.persistence.embed.EmbedXml"
+		access="FIELD">
+		<attributes>
+			<basic name="intVal1"></basic>
+			<basic name="intVal2"></basic>
+			<basic name="intVal3"></basic>
+		</attributes>
+	</embeddable>
+
 </entity-mappings>
\ No newline at end of file

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java?rev=740781&r1=740780&r2=740781&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java Wed Feb  4 16:31:54 2009
@@ -1392,6 +1392,9 @@
         fmd.setSerialized(false); // override any Lob annotation
         if (!fmd.isDefaultFetchGroupExplicit())
             fmd.setInDefaultFetchGroup(true);
+        boolean orphanRemoval = Boolean.valueOf(attrs.getValue(
+            "orphan-removal"));
+        setOrphanRemoval(fmd, orphanRemoval);
     }
 
     /**
@@ -1448,8 +1451,16 @@
             fmd.getElement().setDeclaredType(classForName(val));
         assertPCCollection(fmd, "OneToMany");
         fmd.setSerialized(false); // override any Lob annotation
+        boolean orphanRemoval = Boolean.valueOf(attrs.getValue(
+            "orphan-removal"));
+        setOrphanRemoval(fmd.getElement(), orphanRemoval);
     }
-
+    
+    protected void setOrphanRemoval(ValueMetaData vmd, boolean orphanRemoval) {
+        if (orphanRemoval) 
+            vmd.setCascadeDelete(ValueMetaData.CASCADE_AUTO);
+    }
+    
     protected void parseElementCollection(FieldMetaData fmd, Attributes attrs)
         throws SAXException {
         String val = attrs.getValue("target-entity");