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/03/09 18:08:36 UTC

svn commit: r751766 [1/2] - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persis...

Author: fancy
Date: Mon Mar  9 17:08:34 2009
New Revision: 751766

URL: http://svn.apache.org/viewvc?rev=751766&view=rev
Log:
OPENJPA-967 JPA2 Query support for selection of KEY, VALUE, ENTRY of a Map value
more test scenarios for Map having @MapKeyClass or @MapKeyJoinColumn annotations

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Compny1.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Compny2.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Division.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Item1.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Item2.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/TestSpec10_1_27.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/VicePresident.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/Company.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/Division.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/TestSpec10_1_27_Ex3.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/VicePresident.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/Company.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/Division.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/TestSpec10_1_27_Ex4.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/VicePresident.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/Company.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/Division.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/TestSpec10_1_27_Ex5.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/VicePresident.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex8/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex8/Company.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex8/FileName.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex8/TestSpec10_1_27_Ex8.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex8/VicePresident.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex1/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex1/Company.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex1/Division.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex1/TestSpec10_1_29_Ex1.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex1/VicePresident.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex3/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex3/Course.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex3/Semester.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex3/Student.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex3/TestSpec10_1_29_Ex3.java
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerRelationMapTableFieldStrategy.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationRelationMapTableFieldStrategy.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Company1.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Company2.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Division.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/VicePresident.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerRelationMapTableFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerRelationMapTableFieldStrategy.java?rev=751766&r1=751765&r2=751766&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerRelationMapTableFieldStrategy.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerRelationMapTableFieldStrategy.java Mon Mar  9 17:08:34 2009
@@ -124,7 +124,7 @@
         ValueMapping vm = field.getElementMapping();
         ForeignKey fk = vm.getForeignKey(val);
         if (fk == null)
-            return null;
+            return joins;
         return joins.joinRelation(field.getName(), fk, val,
             vm.getSelectSubclasses(), false, false);
     }
@@ -322,12 +322,15 @@
                 throw RelationStrategies.unjoinable(val);
             return joins;
         }
+        ForeignKey fk = val.getForeignKey(clss[0]);
+        if (fk == null)
+            return joins;
         if (forceOuter)
             return joins.outerJoinRelation(field.getName(),
-                val.getForeignKey(clss[0]), clss[0], val.getSelectSubclasses(),
+                fk, clss[0], val.getSelectSubclasses(),
                 false, false);
         return joins.joinRelation(field.getName(),
-            val.getForeignKey(clss[0]), clss[0], val.getSelectSubclasses(), 
+                fk, clss[0], val.getSelectSubclasses(), 
             false, false);
     }
 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationRelationMapTableFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationRelationMapTableFieldStrategy.java?rev=751766&r1=751765&r2=751766&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationRelationMapTableFieldStrategy.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationRelationMapTableFieldStrategy.java Mon Mar  9 17:08:34 2009
@@ -167,7 +167,7 @@
         ValueMapping vm = field.getElementMapping();
         ForeignKey fk = vm.getForeignKey(val);
         if (fk == null)
-            return null;
+            return joins;
         return joins.joinRelation(field.getName(), fk, val,
             vm.getSelectSubclasses(), false, false);
     }
@@ -364,12 +364,15 @@
                 throw RelationStrategies.unjoinable(val);
             return joins;
         }
+        ForeignKey fk = val.getForeignKey(clss[0]);
+        if (fk == null)
+            return joins;
         if (forceOuter)
             return joins.outerJoinRelation(field.getName(),
-                val.getForeignKey(clss[0]), clss[0], val.getSelectSubclasses(),
+                fk, clss[0], val.getSelectSubclasses(),
                 false, false);
         return joins.joinRelation(field.getName(),
-            val.getForeignKey(clss[0]), clss[0], val.getSelectSubclasses(),
+            fk, clss[0], val.getSelectSubclasses(),
             false, false);
     }
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Company1.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Company1.java?rev=751766&r1=751765&r2=751766&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Company1.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Company1.java Mon Mar  9 17:08:34 2009
@@ -24,6 +24,7 @@
 import javax.persistence.*;
 
 @Entity
+@Table(schema="embed", name="Comp1")
 public class Company1 {
     @Id
     int id;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Company2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Company2.java?rev=751766&r1=751765&r2=751766&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Company2.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Company2.java Mon Mar  9 17:08:34 2009
@@ -24,6 +24,7 @@
 import javax.persistence.*;
 
 @Entity
+@Table(schema="embed", name="Comp2")
 public class Company2 {
     @Id
     int id;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Division.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Division.java?rev=751766&r1=751765&r2=751766&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Division.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Division.java Mon Mar  9 17:08:34 2009
@@ -20,8 +20,10 @@
 
 import javax.persistence.Entity;
 import javax.persistence.Id;
+import javax.persistence.Table;
 
 @Entity
+@Table(schema="embed", name="Division")
 public class Division {
     @Id
     int id;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/VicePresident.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/VicePresident.java?rev=751766&r1=751765&r2=751766&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/VicePresident.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/VicePresident.java Mon Mar  9 17:08:34 2009
@@ -21,6 +21,7 @@
 import javax.persistence.*;
 
 @Entity
+@Table(schema="embed", name="VP")
 public class VicePresident {
     @Id
     int id;

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Compny1.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Compny1.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Compny1.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Compny1.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,51 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex0;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name="S27x0Comp1")
+public class Compny1 {
+    @Id
+    int id;
+
+    @OneToMany(targetEntity=VicePresident.class)
+    @MapKeyClass(Division.class)
+    Map orgs = new HashMap();
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public Map getOrganization() {
+        return orgs;
+    }
+
+    public void addToOrganization(Division division, VicePresident vp) {
+        orgs.put(division, vp);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Compny2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Compny2.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Compny2.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Compny2.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,50 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex0;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.*;
+
+@Entity
+public class Compny2 {
+    @Id
+    int id;
+
+    @OneToMany
+    Map<Division, VicePresident> orgs =
+        new HashMap<Division, VicePresident>();
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public Map getOrganization() {
+        return orgs;
+    }
+
+    public void addToOrganization(Division division, VicePresident vp) {
+        orgs.put(division, vp);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Division.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Division.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Division.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Division.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,64 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex0;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="S27x0Div")
+public class Division {
+    @Id
+    int id;
+
+    String name;
+
+
+    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 boolean equals(Object o) {
+        Division d = (Division) o;
+        if (d.name.equals(name) &&
+            d.getId() == id)
+            return true;
+        return false;
+    }
+
+    public int hashCode() {
+        int ret = 0;
+        ret = ret * 31 + name.hashCode();
+        ret = ret *31 + id;
+        return ret;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Item1.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Item1.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Item1.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Item1.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,51 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex0;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name="S27x0Itm1")
+public class Item1 {
+    @Id
+    int id;
+    
+    @ElementCollection(targetClass=String.class)
+    @MapKeyClass(String.class)
+    Map images = new HashMap();
+    
+    public int getId() {
+        return id;
+    }
+    
+    public void setId(int id) {
+        this.id = id;
+    }
+    
+    public Map<String, String> getImages() {
+        return images;
+    }
+    
+    public void addImage(String imageName, String fileName) {
+        images.put(imageName, fileName);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Item2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Item2.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Item2.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/Item2.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,50 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex0;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name="S27x0Itm2")
+public class Item2 {
+    @Id
+    int id;
+    
+    @ElementCollection
+    Map<String, String> images = new HashMap<String, String>();
+    
+    public int getId() {
+        return id;
+    }
+    
+    public void setId(int id) {
+        this.id = id;
+    }
+    
+    public Map<String, String> getImages() {
+        return images;
+    }
+    
+    public void addImage(String imageName, String fileName) {
+        images.put(imageName, fileName);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/TestSpec10_1_27.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/TestSpec10_1_27.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/TestSpec10_1_27.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/TestSpec10_1_27.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,315 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex0;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Query;
+
+import junit.framework.Assert;
+
+import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
+import org.apache.openjpa.lib.jdbc.JDBCEvent;
+import org.apache.openjpa.lib.jdbc.JDBCListener;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestSpec10_1_27 extends SingleEMFTestCase {
+    public int numItems = 2;
+    public int numImagesPerItem = 3;
+    public int numCompany = 2;
+    public int numDivisionsPerCo = 2;
+    public int itemId = 1;
+    public int compId = 1;
+    public int divId = 1;
+    public int vpId = 1;
+
+    public List<String> namedQueries = new ArrayList<String>();
+    protected List<String> sql = new ArrayList<String>();
+    protected int sqlCount;
+
+    public void setUp() {
+        super.setUp(CLEAR_TABLES,
+                Compny1.class, Compny2.class,
+                Item1.class, Item2.class,
+                Division.class, VicePresident.class,
+                "openjpa.jdbc.JDBCListeners", 
+                new JDBCListener[] { this.new Listener() });
+        createObj(emf);
+    }
+
+    public void testQueryQualifiedId() throws Exception {
+        EntityManager em = emf.createEntityManager();
+
+        String query = "select KEY(e) from Compny1 c, " +
+            " in (c.orgs) e order by c.id";
+        List rs = em.createQuery(query).getResultList();
+        Division d = (Division) rs.get(0);
+
+        em.clear();
+        String query4 = "select ENTRY(e) from Compny1 c, " +
+        " in (c.orgs) e order by c.id";
+        List rs4 = em.createQuery(query4).getResultList();
+        Map.Entry me = (Map.Entry) rs4.get(0);
+
+        assertTrue(d.equals(me.getKey()));
+
+        query = "select KEY(e) from Compny2 c, " +
+            " in (c.orgs) e order by c.id";
+        rs = em.createQuery(query).getResultList();
+        d = (Division) rs.get(0);
+
+        em.clear();
+        query4 = "select ENTRY(e) from Compny2 c, " +
+            " in (c.orgs) e order by c.id";
+        rs4 = em.createQuery(query4).getResultList();
+        me = (Map.Entry) rs4.get(0);
+
+        assertTrue(d.equals(me.getKey()));
+
+        em.close();
+    }
+
+    public void testQueryObj() throws Exception {
+        queryObj(emf);
+    }
+
+    public List<String> getSql() {
+        return sql;
+    }
+
+    public int getSqlCount() {
+        return sqlCount;
+    }
+
+    public void createObj(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        for (int i = 0; i < numItems; i++)
+            createItem1(em, itemId++);
+        for (int i = 0; i < numItems; i++)
+            createItem2(em, itemId++);
+        for (int i = 0; i < numCompany; i++)
+            createCompany1(em, compId++);
+        for (int i = 0; i < numCompany; i++)
+            createCompany2(em, compId++);
+        tran.begin();
+        em.flush();
+        tran.commit();
+        em.close();
+    }
+
+    public void createItem1(EntityManager em, int id) {
+        Item1 item = new Item1();
+        item.setId(id);
+        for (int i = 0; i < numImagesPerItem; i++) {
+            item.addImage("image" + id + i, "file" + id + i);
+        }
+        em.persist(item);
+    }
+
+    public void createItem2(EntityManager em, int id) {
+        Item2 item = new Item2();
+        item.setId(id);
+        for (int i = 0; i < numImagesPerItem; i++) {
+            item.addImage("image" + id + i, "file" + id + i);
+        }
+        em.persist(item);
+    }
+
+    public void createCompany1(EntityManager em, int id) {
+        Compny1 c = new Compny1();
+        c.setId(id);
+        for (int i = 0; i < numDivisionsPerCo; i++) {
+            Division d = createDivision(em, divId++);
+            VicePresident vp = createVicePresident(em, vpId++);
+            c.addToOrganization(d, vp);
+            em.persist(d);
+            em.persist(vp);
+        }
+        em.persist(c);
+    }
+
+    public void createCompany2(EntityManager em, int id) {
+        Compny2 c = new Compny2();
+        c.setId(id);
+        for (int i = 0; i < numDivisionsPerCo; i++) {
+            Division d = createDivision(em, divId++);
+            VicePresident vp = createVicePresident(em, vpId++);
+            c.addToOrganization(d, vp);
+            em.persist(d);
+            em.persist(vp);
+        }
+        em.persist(c);
+    }
+
+    public Division createDivision(EntityManager em, int id) {
+        Division d = new Division();
+        d.setId(id);
+        d.setName("d" + id);
+        return d;
+    }
+
+    public VicePresident createVicePresident(EntityManager em, int id) {
+        VicePresident vp = new VicePresident();
+        vp.setId(id);
+        vp.setName("vp" + id);
+        return vp;
+    }
+
+    public void findObj(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+
+        Item1 item1 = em.find(Item1.class, 1);
+        assertItem1(item1);
+
+        Item2 item2 = em.find(Item2.class, 4);
+        assertItem2(item2);
+
+        Compny1 c1 = em.find(Compny1.class, 1);
+        assertCompany1(c1);
+
+        Compny2 c2 = em.find(Compny2.class, 3);
+        assertCompany2(c2);
+
+        Division d = em.find(Division.class, 1);
+        assertDivision(d);
+
+        VicePresident vp = em.find(VicePresident.class, 1);
+        assertVicePresident(vp);
+    }
+
+    public void assertItem1(Item1 item) {
+        int id = item.getId();
+        Map images = item.getImages();
+        Assert.assertEquals(numImagesPerItem, images.size());
+    }
+
+    public void assertItem2(Item2 item) {
+        int id = item.getId();
+        Map images = item.getImages();
+        Assert.assertEquals(numImagesPerItem, images.size());
+    }
+
+    public void assertCompany1(Compny1 c) {
+        int id = c.getId();
+        Map organization = c.getOrganization();
+        Assert.assertEquals(2,organization.size());
+    }
+
+    public void assertCompany2(Compny2 c) {
+        int id = c.getId();
+        Map organization = c.getOrganization();
+        Assert.assertEquals(2,organization.size());
+    }    
+
+    public void assertDivision(Division d) {
+        int id = d.getId();
+        String name = d.getName();
+    }
+
+    public void assertVicePresident(VicePresident vp) {
+        int id = vp.getId();
+        String name = vp.getName();
+    }
+
+    public void queryObj(EntityManagerFactory emf) {
+        queryItem(emf);
+        queryCompany(emf);
+        queryDivision(emf);
+        queryVicePresident(emf);
+    }
+
+    public void queryItem(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        Query q1 = em.createQuery("select i from Item1 i");
+        List<Item1> is1 = q1.getResultList();
+        for (Item1 item : is1){
+            assertItem1(item);
+        }
+
+        Query q2 = em.createQuery("select i from Item2 i");
+        List<Item2> is2 = q2.getResultList();
+        for (Item2 item : is2){
+            assertItem2(item);
+        }
+        tran.commit();
+        em.close();
+    }
+
+    public void queryCompany(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        Query q1 = em.createQuery("select c from Compny1 c");
+        List<Compny1> cs1 = q1.getResultList();
+        for (Compny1 c : cs1){
+            assertCompany1(c);
+        }
+        Query q2 = em.createQuery("select c from Compny2 c");
+        List<Compny2> cs2 = q2.getResultList();
+        for (Compny2 c : cs2){
+            assertCompany2(c);
+        }
+        tran.commit();
+        em.close();
+    }
+
+    public void queryDivision(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        Query q = em.createQuery("select d from Division d");
+        List<Division> ds = q.getResultList();
+        for (Division d : ds){
+            assertDivision(d);
+        }
+        tran.commit();
+        em.close();
+    }
+
+    public void queryVicePresident(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        Query q = em.createQuery("select vp from VicePresident vp");
+        List<VicePresident> vps = q.getResultList();
+        for (VicePresident vp : vps){
+            assertVicePresident(vp);
+        }
+        tran.commit();
+        em.close();
+    }    
+
+    public class Listener extends AbstractJDBCListener {
+        @Override
+        public void beforeExecuteStatement(JDBCEvent event) {
+            if (event.getSQL() != null && sql != null) {
+                sql.add(event.getSQL());
+                sqlCount++;
+            }
+        }
+    }
+}
\ No newline at end of file

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/VicePresident.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/VicePresident.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/VicePresident.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/VicePresident.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,51 @@
+package org.apache.openjpa.persistence.jdbc.maps.spec_10_1_27_ex0;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name="S27x0VP")
+public class VicePresident {
+    @Id
+    int id;
+    
+    String name;
+  
+    @ManyToOne
+    Compny1 co;
+    
+    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 Compny1 getCompany() {
+        return co;
+    }
+    
+    public void setCompany(Compny1 co) {
+        this.co = co;
+    }
+
+    public boolean equals(Object v) {
+        if (this == v)
+            return true;
+        if (!(v instanceof VicePresident))
+            return false;
+        VicePresident o = (VicePresident) v;
+        if (this.id == o.getId() &&
+            this.name.equals(o.getName()))
+            return true;
+        return false;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/Company.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/Company.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/Company.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/Company.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,59 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex3;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name="S27x3Comp")
+public class Company {
+    @Id
+    int id;
+    
+    @OneToMany(targetEntity=VicePresident.class , mappedBy="co")
+    @MapKeyClass(Division.class)
+    Map orgs = new HashMap();
+    
+    public int getId() {
+        return id;
+    }
+    
+    public void setId(int id) {
+        this.id = id;
+    }
+    
+    public Map getOrganization() {
+        return orgs;
+    }
+    
+    public void addToOrganization(Division division, VicePresident vp) {
+        orgs.put(division, vp);
+    }
+    
+    public void removeFromOrganization(Division d) {
+        orgs.remove(d);
+    }
+    
+    public VicePresident getOrganization(Division d) {
+        return (VicePresident)orgs.get(d);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/Division.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/Division.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/Division.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/Division.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,64 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex3;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="S27x3Div")
+public class Division {
+    @Id
+    int id;
+    
+    String name;
+    
+    
+    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 boolean equals(Object o) {
+        Division d = (Division) o;
+        if (d.name.equals(name) &&
+            d.getId() == id)
+            return true;
+        return false;
+    }
+
+    public int hashCode() {
+        int ret = 0;
+        ret = ret * 31 + name.hashCode();
+        ret = ret *31 + id;
+        return ret;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/TestSpec10_1_27_Ex3.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/TestSpec10_1_27_Ex3.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/TestSpec10_1_27_Ex3.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/TestSpec10_1_27_Ex3.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,286 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex3;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Query;
+
+import junit.framework.Assert;
+
+import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
+import org.apache.openjpa.lib.jdbc.JDBCEvent;
+import org.apache.openjpa.lib.jdbc.JDBCListener;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestSpec10_1_27_Ex3 extends SingleEMFTestCase {
+    public int numCompany = 2;
+    public int numDivisionsPerCo = 2;
+    public List<String> namedQueries = new ArrayList<String>();
+
+    public int compId = 1;
+    public int divId = 1;
+    public int vpId = 1;
+    public int newDivId = 100;
+    public int newVpId = 100;
+
+    protected List<String> sql = new ArrayList<String>();
+    protected int sqlCount;
+
+    public void setUp() {
+        super.setUp(CLEAR_TABLES,
+            Company.class,
+            Division.class,
+            VicePresident.class,
+            "openjpa.jdbc.JDBCListeners", 
+            new JDBCListener[] { this.new Listener() });
+        createObj(emf);
+    }
+
+    public void testQueryObj() throws Exception {
+        queryObj(emf);
+    }
+
+    public void testQueryQualifiedId() throws Exception {
+        EntityManager em = emf.createEntityManager();
+
+        String query = "select KEY(e) from Company c, " +
+            " in (c.orgs) e order by c.id";
+        List rs = em.createQuery(query).getResultList();
+        Division d = (Division) rs.get(0);
+
+        em.clear();
+        String query4 = "select ENTRY(e) from Company c, " +
+            " in (c.orgs) e order by c.id";
+        List rs4 = em.createQuery(query4).getResultList();
+        Map.Entry me = (Map.Entry) rs4.get(0);
+
+        assertTrue(d.equals(me.getKey()));
+
+        em.clear();
+        query = "select KEY(e) from Company c " +
+            " left join c.orgs e order by c.id";
+        rs = em.createQuery(query).getResultList();
+        d = (Division) rs.get(0);
+
+        em.clear();
+        query4 = "select ENTRY(e) from Company c " +
+            " left join c.orgs e order by c.id";
+        rs4 = em.createQuery(query4).getResultList();
+        me = (Map.Entry) rs4.get(0);
+
+        assertTrue(d.equals(me.getKey()));
+
+        em.close();
+    }
+
+    public List<String> getSql() {
+        return sql;
+    }
+
+    public int getSqlCount() {
+        return sqlCount;
+    }
+
+    public void createObj(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        for (int i = 0; i < numCompany; i++)
+            createCompany(em, compId++);
+        tran.begin();
+        em.flush();
+        tran.commit();
+        em.close();
+    }
+
+    public void createCompany(EntityManager em, int id) {
+        Company c = new Company();
+        c.setId(id);
+        for (int i = 0; i < numDivisionsPerCo; i++) {
+            Division d = createDivision(em, divId++);
+            VicePresident vp = createVicePresident(em, vpId++);
+            c.addToOrganization(d, vp);
+            vp.setCompany(c);
+            em.persist(d);
+            em.persist(vp);
+        }
+        em.persist(c);
+    }
+
+    public Division createDivision(EntityManager em, int id) {
+        Division d = new Division();
+        d.setId(id);
+        d.setName("d" + id);
+        return d;
+    }
+
+    public VicePresident createVicePresident(EntityManager em, int id) {
+        VicePresident vp = new VicePresident();
+        vp.setId(id);
+        vp.setName("vp" + id);
+        return vp;
+    }
+
+    public void findObj(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        Company c = em.find(Company.class, 1);
+        assertCompany(c);
+
+        Division d = em.find(Division.class, 1);
+        assertDivision(d);
+
+        VicePresident vp = em.find(VicePresident.class, 1);
+        assertVicePresident(vp);
+
+        updateObj(em, c);
+        em.close();
+
+        em = emf.createEntityManager();
+        c = em.find(Company.class, 1);
+        assertCompany(c);
+        deleteObj(em, c);
+        em.close();
+    }
+
+    public void updateObj(EntityManager em, Company c) {
+        EntityTransaction tran = em.getTransaction();
+        // remove an element
+        tran.begin();
+        Map orgs = c.getOrganization();
+        Set keys = orgs.keySet();
+        for (Object key : keys) {
+            Division d = (Division) key;
+            VicePresident vp = c.getOrganization(d);
+            vp.setCompany(null);
+            em.persist(vp);
+            c.removeFromOrganization(d);
+            break;
+        }
+        em.persist(c);
+        em.flush();
+        tran.commit();
+
+        // add an element
+        tran.begin();
+        Division d = createDivision(em, newDivId++);
+        VicePresident vp = createVicePresident(em, newVpId++);
+        c.addToOrganization(d, vp);
+        vp.setCompany(c);
+        em.persist(d);
+        em.persist(vp);
+        em.persist(c);
+        em.flush();
+        tran.commit();
+
+        // modify an element
+        tran.begin();
+        orgs = c.getOrganization();
+        vp = c.getOrganization(d);
+        vp.setName("newNameAgain");
+        em.persist(c);
+        em.persist(vp);
+        em.flush();
+        tran.commit();
+    }       
+
+    public void deleteObj(EntityManager em, Company c) {
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        em.remove(c);
+        tran.commit();
+    }
+
+    public void assertCompany(Company c) {
+        int id = c.getId();
+        Map organization = c.getOrganization();
+        Assert.assertEquals(2,organization.size());
+    }
+
+    public void assertDivision(Division d) {
+        int id = d.getId();
+        String name = d.getName();
+    }
+
+    public void assertVicePresident(VicePresident vp) {
+        int id = vp.getId();
+        String name = vp.getName();
+    }
+
+
+    public void queryObj(EntityManagerFactory emf) {
+        queryCompany(emf);
+        queryDivision(emf);
+        queryVicePresident(emf);
+    }
+
+    public void queryCompany(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        Query q = em.createQuery("select c from Company c");
+        List<Company> cs = q.getResultList();
+        for (Company c : cs){
+            assertCompany(c);
+        }
+        tran.commit();
+        em.close();
+    }
+
+    public void queryDivision(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        Query q = em.createQuery("select d from Division d");
+        List<Division> ds = q.getResultList();
+        for (Division d : ds){
+            assertDivision(d);
+        }
+        tran.commit();
+        em.close();
+    }
+
+    public void queryVicePresident(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        Query q = em.createQuery("select vp from VicePresident vp");
+        List<VicePresident> vps = q.getResultList();
+        for (VicePresident vp : vps){
+            assertVicePresident(vp);
+        }
+        tran.commit();
+        em.close();
+    }
+
+    public class Listener extends AbstractJDBCListener {
+        @Override
+        public void beforeExecuteStatement(JDBCEvent event) {
+            if (event.getSQL() != null && sql != null) {
+                sql.add(event.getSQL());
+                sqlCount++;
+            }
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/VicePresident.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/VicePresident.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/VicePresident.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/VicePresident.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex3;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name="S27x3VP")
+public class VicePresident {
+    @Id
+    int id;
+
+    String name;
+
+    @ManyToOne
+    Company co;
+
+    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 Company getCompany() {
+        return co;
+    }
+
+    public void setCompany(Company co) {
+        this.co = co;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/Company.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/Company.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/Company.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/Company.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,59 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex4;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name="S27x4Comp")
+public class Company {
+    @Id
+    int id;
+
+    @OneToMany
+    Map<Division, VicePresident> organization =
+        new HashMap<Division, VicePresident>();
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public Map getOrganization() {
+        return organization;
+    }
+
+    public void addToOrganization(Division division, VicePresident vp) {
+        organization.put(division, vp);
+    }
+
+    public void removeFromOrganization(Division d) {
+        organization.remove(d);
+    }
+
+    public VicePresident getOrganization(Division d) {
+        return organization.get(d);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/Division.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/Division.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/Division.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/Division.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,63 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex4;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="S27x4Div")
+public class Division {
+    @Id
+    int id;
+
+    String name;
+
+    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 boolean equals(Object o) {
+        Division d = (Division) o;
+        if (d.name.equals(name) &&
+            d.getId() == id)
+            return true;
+        return false;
+    }
+
+    public int hashCode() {
+        int ret = 0;
+        ret = ret * 31 + name.hashCode();
+        ret = ret *31 + id;
+        return ret;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/TestSpec10_1_27_Ex4.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/TestSpec10_1_27_Ex4.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/TestSpec10_1_27_Ex4.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/TestSpec10_1_27_Ex4.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,285 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex4;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Query;
+
+import junit.framework.Assert;
+
+import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
+import org.apache.openjpa.lib.jdbc.JDBCEvent;
+import org.apache.openjpa.lib.jdbc.JDBCListener;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestSpec10_1_27_Ex4 extends SingleEMFTestCase {
+    public int numCompany = 2;
+    public int numDivisionsPerCo = 2;
+    public List<String> namedQueries = new ArrayList<String>();
+
+    public int compId = 1;
+    public int divId = 1;
+    public int vpId = 1;
+    public int newDivId = 100;
+    public int newVpId = 100;
+
+    protected List<String> sql = new ArrayList<String>();
+    protected int sqlCount;
+
+    public void setUp() {
+        super.setUp(CLEAR_TABLES,
+            Company.class,
+            Division.class,
+            VicePresident.class,
+            "openjpa.jdbc.JDBCListeners", 
+            new JDBCListener[] { this.new Listener() });
+        createObj(emf);
+    }
+
+    public void testQueryObj() throws Exception {
+        queryObj(emf);
+    }
+
+    public void testQueryQualifiedId() throws Exception {
+        EntityManager em = emf.createEntityManager();
+
+        String query = "select KEY(e) from Company c, " +
+            " in (c.organization) e order by c.id";
+        List rs = em.createQuery(query).getResultList();
+        Division d = (Division) rs.get(0);
+
+        em.clear();
+        String query4 = "select ENTRY(e) from Company c, " +
+            " in (c.organization) e order by c.id";
+        List rs4 = em.createQuery(query4).getResultList();
+        Map.Entry me = (Map.Entry) rs4.get(0);
+
+        assertTrue(d.equals(me.getKey()));
+
+        em.clear();
+        query = "select KEY(e) from Company c " +
+            " left join c.organization e order by c.id";
+        rs = em.createQuery(query).getResultList();
+        d = (Division) rs.get(0);
+
+        em.clear();
+        query4 = "select ENTRY(e) from Company c " +
+            " left join c.organization e order by c.id";
+        rs4 = em.createQuery(query4).getResultList();
+        me = (Map.Entry) rs4.get(0);
+
+        assertTrue(d.equals(me.getKey()));
+
+        em.close();
+    }
+
+    public List<String> getSql() {
+        return sql;
+    }
+
+    public int getSqlCount() {
+        return sqlCount;
+    }
+
+    public void createObj(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        for (int i = 0; i < numCompany; i++)
+            createCompany(em, compId++);
+        tran.begin();
+        em.flush();
+        tran.commit();
+        em.close();
+    }
+
+    public void createCompany(EntityManager em, int id) {
+        Company c = new Company();
+        c.setId(id);
+        for (int i = 0; i < numDivisionsPerCo; i++) {
+            Division d = createDivision(em, divId++);
+            VicePresident vp = createVicePresident(em, vpId++);
+            c.addToOrganization(d, vp);
+            em.persist(d);
+            em.persist(vp);
+        }
+        em.persist(c);
+    }
+
+    public Division createDivision(EntityManager em, int id) {
+        Division d = new Division();
+        d.setId(id);
+        d.setName("d" + id);
+        return d;
+    }
+
+    public VicePresident createVicePresident(EntityManager em, int id) {
+        VicePresident vp = new VicePresident();
+        vp.setId(id);
+        vp.setName("vp" + id);
+        return vp;
+    }
+
+    public void findObj(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        Company c = em.find(Company.class, 1);
+        assertCompany(c);
+
+        Division d = em.find(Division.class, 1);
+        assertDivision(d);
+
+        VicePresident vp = em.find(VicePresident.class, 1);
+        assertVicePresident(vp);
+
+        updateObj(em, c);
+        em.close();
+
+        em = emf.createEntityManager();
+        c = em.find(Company.class, 1);
+        assertCompany(c);
+        deleteObj(em, c);
+        em.close();
+    }
+
+    public void updateObj(EntityManager em, Company c) {
+        EntityTransaction tran = em.getTransaction();
+        // remove an element
+        tran.begin();
+        Map orgs = c.getOrganization();
+        Set keys = orgs.keySet();
+        for (Object key : keys) {
+            Division d = (Division)key;
+            VicePresident vp = c.getOrganization(d);
+            vp.setCompany(null);
+            em.persist(vp);
+            orgs.remove(d);
+            break;
+        }
+        em.persist(c);
+        em.flush();
+        tran.commit();
+
+        // add an element
+        tran.begin();
+        Division d = createDivision(em, newDivId++);
+        VicePresident vp = createVicePresident(em, newVpId++);
+        c.addToOrganization(d, vp);
+        vp.setCompany(c);
+        em.persist(d);
+        em.persist(vp);
+        em.persist(c);
+        em.flush();
+        tran.commit();
+
+        // modify an element
+        tran.begin();
+        vp = c.getOrganization(d);
+        vp.setName("newAgain");
+        em.persist(vp);
+        em.persist(c);
+        em.flush();
+        tran.commit();
+
+    }	
+
+    public void deleteObj(EntityManager em, Company c) {
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        em.remove(c);
+        tran.commit();
+    }
+
+    public void assertCompany(Company c) {
+        int id = c.getId();
+        Map organization = c.getOrganization();
+        Assert.assertEquals(2,organization.size());
+    }
+
+    public void assertDivision(Division d) {
+        int id = d.getId();
+        String name = d.getName();
+    }
+
+    public void assertVicePresident(VicePresident vp) {
+        int id = vp.getId();
+        String name = vp.getName();
+    }
+
+
+    public void queryObj(EntityManagerFactory emf) {
+        queryCompany(emf);
+        queryDivision(emf);
+        queryVicePresident(emf);
+    }
+
+    public void queryCompany(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        Query q = em.createQuery("select c from Company c");
+        List<Company> cs = q.getResultList();
+        for (Company c : cs){
+            assertCompany(c);
+        }
+        tran.commit();
+        em.close();
+    }
+
+    public void queryDivision(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        Query q = em.createQuery("select d from Division d");
+        List<Division> ds = q.getResultList();
+        for (Division d : ds){
+            assertDivision(d);
+        }
+        tran.commit();
+        em.close();
+    }
+
+    public void queryVicePresident(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        Query q = em.createQuery("select vp from VicePresident vp");
+        List<VicePresident> vps = q.getResultList();
+        for (VicePresident vp : vps){
+            assertVicePresident(vp);
+        }
+        tran.commit();
+        em.close();
+    }
+
+    public class Listener extends AbstractJDBCListener {
+        @Override
+        public void beforeExecuteStatement(JDBCEvent event) {
+            if (event.getSQL() != null && sql != null) {
+                sql.add(event.getSQL());
+                sqlCount++;
+            }
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/VicePresident.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/VicePresident.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/VicePresident.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/VicePresident.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex4;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name="S27x4VP")
+public class VicePresident {
+    @Id
+    int id;
+
+    String name;
+
+    @ManyToOne
+    Company co;
+
+    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 Company getCompany() {
+        return co;
+    }
+
+    public void setCompany(Company co) {
+        this.co = co;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/Company.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/Company.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/Company.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/Company.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,59 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex5;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name="S27x5Comp")
+public class Company {
+    @Id
+    int id;
+
+    @OneToMany(mappedBy="co")
+    Map<Division, VicePresident> orgs =
+        new HashMap<Division, VicePresident>();
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public Map getOrganization() {
+        return orgs;
+    }
+
+    public void addToOrganization(Division division, VicePresident vp) {
+        orgs.put(division, vp);
+    }
+
+    public void removeFromOrganization(Division d) {
+        orgs.remove(d);
+    }
+
+    public VicePresident getOrganization(Division d) {
+        return orgs.get(d);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/Division.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/Division.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/Division.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/Division.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,63 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex5;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="S27x5Div")
+public class Division {
+    @Id
+    int id;
+
+    String name;
+
+    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 boolean equals(Object o) {
+        Division d = (Division) o;
+        if (d.name.equals(name) &&
+            d.getId() == id)
+            return true;
+        return false;
+    }
+
+    public int hashCode() {
+        int ret = 0;
+        ret = ret * 31 + name.hashCode();
+        ret = ret *31 + id;
+        return ret;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/TestSpec10_1_27_Ex5.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/TestSpec10_1_27_Ex5.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/TestSpec10_1_27_Ex5.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/TestSpec10_1_27_Ex5.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,327 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex5;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Query;
+
+import junit.framework.Assert;
+
+import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
+import org.apache.openjpa.lib.jdbc.JDBCEvent;
+import org.apache.openjpa.lib.jdbc.JDBCListener;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestSpec10_1_27_Ex5 extends SingleEMFTestCase {
+    public int numCompany = 2;
+    public int numDivisionsPerCo = 2;
+    public List<String> namedQueries = new ArrayList<String>();
+    
+    public int compId = 1;
+    public int divId = 1;
+    public int vpId = 1;
+    public int newDivId = 100;
+    public int newVpId = 100;
+    
+    protected List<String> sql = new ArrayList<String>();
+    protected int sqlCount;
+
+    public void setUp() {
+        super.setUp(CLEAR_TABLES,
+            Company.class,
+            Division.class,
+            VicePresident.class,
+            "openjpa.jdbc.JDBCListeners", 
+            new JDBCListener[] { this.new Listener() });
+        createObj(emf);
+    }
+
+    public void testQueryObj() throws Exception {
+        queryObj(emf);
+    }
+
+    public void testQueryQualifiedId() throws Exception {
+        EntityManager em = emf.createEntityManager();
+
+        String query = "select KEY(e) from Company c, " +
+            " in (c.orgs) e order by c.id";
+        List rs = em.createQuery(query).getResultList();
+        Division d = (Division) rs.get(0);
+
+        em.clear();
+        String query4 = "select ENTRY(e) from Company c, " +
+            " in (c.orgs) e order by c.id";
+        List rs4 = em.createQuery(query4).getResultList();
+        Map.Entry me = (Map.Entry) rs4.get(0);
+
+        assertTrue(d.equals(me.getKey()));
+
+        em.clear();
+        query = "select KEY(e) from Company c " +
+            " left join c.orgs e order by c.id";
+        rs = em.createQuery(query).getResultList();
+        d = (Division) rs.get(0);
+
+        em.clear();
+        query4 = "select ENTRY(e) from Company c " +
+            " left join c.orgs e order by c.id";
+        rs4 = em.createQuery(query4).getResultList();
+        me = (Map.Entry) rs4.get(0);
+
+        assertTrue(d.equals(me.getKey()));
+
+        em.close();
+    }
+    
+	public List<String> getSql() {
+	    return sql;
+	}
+	
+	public int getSqlCount() {
+	    return sqlCount;
+	}
+	
+	public void createObj(EntityManagerFactory emf) {
+		EntityManager em = emf.createEntityManager();
+		EntityTransaction tran = em.getTransaction();
+		for (int i = 0; i < numCompany; i++)
+		    createCompany(em, compId++);
+		tran.begin();
+		em.flush();
+		tran.commit();
+        em.close();
+	}
+
+	public void createCompany(EntityManager em, int id) {
+        Company c = new Company();
+        c.setId(id);
+        for (int i = 0; i < numDivisionsPerCo; i++) {
+            Division d = createDivision(em, divId++);
+            VicePresident vp = createVicePresident(em, vpId++);
+            c.addToOrganization(d, vp);
+            vp.setCompany(c);
+            em.persist(d);
+            em.persist(vp);
+        }
+        em.persist(c);
+ 	}
+	
+    public Division createDivision(EntityManager em, int id) {
+        Division d = new Division();
+        d.setId(id);
+        d.setName("d" + id);
+        return d;
+    }
+	
+    public VicePresident createVicePresident(EntityManager em, int id) {
+        VicePresident vp = new VicePresident();
+        vp.setId(id);
+        vp.setName("vp" + id);
+        return vp;
+    }
+	
+	public void findObj(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+ 	    Company c = em.find(Company.class, 1);
+	    assertCompany(c);
+	    
+        Division d = em.find(Division.class, 1);
+        assertDivision(d);
+        
+        VicePresident vp = em.find(VicePresident.class, 1);
+        assertVicePresident(vp);
+        
+        updateObj1(em, c);
+        
+/*        
+        updateObj(em, c);
+        em.close();
+        
+        em = emf.createEntityManager();
+        c = em.find(Company.class, 1);
+        assertCompany(c);
+        deleteObj(em, c);
+	    em.close();
+*/	    
+	}
+
+    public void updateObj1(EntityManager em, Company c) {
+        EntityTransaction tran = em.getTransaction();
+        // remove an element
+        tran.begin();
+        Map orgs = c.getOrganization();
+        VicePresident vp = null;
+        Set keys = orgs.keySet();
+        for (Object key : keys) {
+            Division d = (Division)key;
+            vp = c.getOrganization(d);
+            vp.setCompany(null);
+            em.persist(vp);
+            c.removeFromOrganization(d);
+            break;
+        }
+        em.persist(c);
+        em.flush();
+        tran.commit();
+        
+        tran.begin();
+        em.remove(c);
+        em.flush();
+        tran.commit();
+        
+        tran.begin();
+        Company c1 = new Company();
+        c1.setId(1);
+        Division d = createDivision(em, divId++);
+        c1.addToOrganization(d, vp);
+        vp.setCompany(c1);
+        em.persist(d);
+        em.persist(c1);
+        em.flush();
+        tran.commit();
+    }
+    
+    public void updateObj(EntityManager em, Company c) {
+        EntityTransaction tran = em.getTransaction();
+        // remove an element
+        tran.begin();
+        Map orgs = c.getOrganization();
+        Set keys = orgs.keySet();
+        for (Object key : keys) {
+            Division d = (Division)key;
+            VicePresident vp = c.getOrganization(d);
+            vp.setCompany(null);
+            em.persist(vp);
+            c.removeFromOrganization(d);
+            break;
+        }
+        em.persist(c);
+        em.flush();
+        tran.commit();
+        
+        // add an element
+        tran.begin();
+        Division d = createDivision(em, newDivId++);
+        VicePresident vp = createVicePresident(em, newVpId++);
+        c.addToOrganization(d, vp);
+        vp.setCompany(c);
+        em.persist(d);
+        em.persist(vp);
+        em.persist(c);
+        em.flush();
+        tran.commit();
+        
+        // modify an element
+        tran.begin();
+        vp = c.getOrganization(d);
+        vp.setName("newAgain");
+        em.persist(vp);
+        em.persist(c);
+        em.flush();
+        tran.commit();
+        
+    }   
+
+    public void deleteObj(EntityManager em, Company c) {
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        em.remove(c);
+        tran.commit();
+    }
+    
+	public void assertCompany(Company c) {
+        int id = c.getId();
+        Map organization = c.getOrganization();
+        Assert.assertEquals(2,organization.size());
+	}
+	
+    public void assertDivision(Division d) {
+        int id = d.getId();
+        String name = d.getName();
+    }
+
+    public void assertVicePresident(VicePresident vp) {
+        int id = vp.getId();
+        String name = vp.getName();
+    }
+	
+	
+	public void queryObj(EntityManagerFactory emf) {
+        queryCompany(emf);
+        queryDivision(emf);
+        queryVicePresident(emf);
+	}
+	
+	public void queryCompany(EntityManagerFactory emf) {
+		EntityManager em = emf.createEntityManager();
+		EntityTransaction tran = em.getTransaction();
+		tran.begin();
+		Query q = em.createQuery("select c from Company c");
+		List<Company> cs = q.getResultList();
+		for (Company c : cs){
+		    assertCompany(c);
+		}
+		tran.commit();
+		em.close();
+	}
+
+	public void queryDivision(EntityManagerFactory emf) {
+	    EntityManager em = emf.createEntityManager();
+	    EntityTransaction tran = em.getTransaction();
+	    tran.begin();
+	    Query q = em.createQuery("select d from Division d");
+	    List<Division> ds = q.getResultList();
+	    for (Division d : ds){
+	        assertDivision(d);
+	    }
+	    tran.commit();
+	    em.close();
+	}
+
+    public void queryVicePresident(EntityManagerFactory emf) {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        Query q = em.createQuery("select vp from VicePresident vp");
+        List<VicePresident> vps = q.getResultList();
+        for (VicePresident vp : vps){
+            assertVicePresident(vp);
+        }
+        tran.commit();
+        em.close();
+    }
+	
+	public class Listener extends AbstractJDBCListener {
+	    @Override
+	    public void beforeExecuteStatement(JDBCEvent event) {
+	        if (event.getSQL() != null && sql != null) {
+	            sql.add(event.getSQL());
+	            sqlCount++;
+	        }
+	    }
+	}
+}
+

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/VicePresident.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/VicePresident.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/VicePresident.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/VicePresident.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex5;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name="S27x5VP")
+public class VicePresident {
+    @Id
+    int id;
+
+    String name;
+
+    @ManyToOne
+    Company co;
+
+    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 Company getCompany() {
+        return co;
+    }
+
+    public void setCompany(Company co) {
+        this.co = co;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex8/Company.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex8/Company.java?rev=751766&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex8/Company.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex8/Company.java Mon Mar  9 17:08:34 2009
@@ -0,0 +1,59 @@
+/*
+ * 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.jdbc.maps.spec_10_1_27_ex8;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name="S27x8Comp")
+public class Company {
+    @Id
+    int id;
+    
+    @OneToMany(mappedBy="co")
+    Map<FileName, VicePresident> orgs =
+        new HashMap<FileName, VicePresident>();
+    
+    public int getId() {
+        return id;
+    }
+    
+    public void setId(int id) {
+        this.id = id;
+    }
+    
+    public Map getOrganization() {
+        return orgs;
+    }
+    
+    public void addToOrganization(VicePresident vp, FileName fileName) {
+        orgs.put(fileName, vp);
+    }
+    
+    public void removeFromOrganization(FileName fileName) {
+        orgs.remove(fileName);
+    }
+
+    public VicePresident getOrganization(FileName fileName) {
+        return orgs.get(fileName);
+    }
+}