OPENJPA-1527: fix AssociationOverride on the key of map where the key is an embeddable via orm.xml.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@915593 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Fay Wang 2010-02-23 23:46:26 +00:00
parent 11c299d895
commit 7f319c4473
6 changed files with 125 additions and 0 deletions

View File

@ -26,6 +26,8 @@ import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.DiscriminatorType;
import javax.persistence.EnumType;
import javax.persistence.InheritanceType;
@ -56,11 +58,13 @@ import org.apache.openjpa.jdbc.sql.DBDictionary;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.meta.SourceTracker;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.meta.AccessCode;
import org.apache.openjpa.meta.ClassMetaData;
import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.persistence.XMLPersistenceMetaDataParser;
import org.apache.openjpa.util.InternalException;
import org.apache.openjpa.util.MetaDataException;
import org.apache.openjpa.util.UserException;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
@ -1390,6 +1394,27 @@ public class XMLPersistenceMappingParser
}
return null;
}
/**
* Process all deferred embeddables using an unknown access type.
*/
protected void addDeferredEmbeddableMetaData() {
super.addDeferredEmbeddableMetaData();
if (_deferredMappings.size() > 0) {
Set<Class<?>> keys = _deferredMappings.keySet();
Class[] classes = keys.toArray(new Class[0]);
for (int i = 0; i < classes.length; i++) {
try {
applyDeferredEmbeddableOverrides(classes[i]);
} catch (Exception e) {
throw new MetaDataException(
_loc.get("no-embeddable-metadata",
classes[i].getName()), e);
}
}
}
}
// Inner class for storing override information
class DeferredEmbeddableOverrides {

View File

@ -82,6 +82,9 @@ public class TestAssocOverridesXML extends AbstractPersistenceTestCase{
assertSQLFragnments(_sql, "CREATE TABLE XML_EMBALIST .*" +
" .*emba_entb.*emba_mentb");
assertSQLFragnments(_sql, "CREATE TABLE XML_EMBAMAP_1 .*" +
" .*key_emba_entb.*key_emba_mentb" +
" .*value_emba_entb.*value_emba_mentb");
}
finally {
try {

View File

@ -0,0 +1,52 @@
/*
* 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.attrOverrides;
public class XMLAssocOverEmbedB {
private String name;
private XMLAssocOverEntityB eb;
private XMLAssocOverEntityB meb;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setEb(XMLAssocOverEntityB eb) {
this.eb = eb;
}
public XMLAssocOverEntityB getEb() {
return eb;
}
public void setMeb(XMLAssocOverEntityB meb) {
this.meb = meb;
}
public XMLAssocOverEntityB getMeb() {
return meb;
}
}

View File

@ -19,12 +19,16 @@
package org.apache.openjpa.persistence.embed.attrOverrides;
import java.util.List;
import java.util.Map;
public class XMLAssocOverEntityA {
private int id;
private List<XMLAssocOverEmbed> embaList;
private Map<XMLAssocOverEmbedB, XMLAssocOverEmbed> embaMap;
public void setEmbA(List<XMLAssocOverEmbed> embA) {
this.embaList = embA;
@ -34,6 +38,14 @@ public class XMLAssocOverEntityA {
return embaList;
}
public void setEmbAMap(Map<XMLAssocOverEmbedB, XMLAssocOverEmbed> embAMap) {
this.embaMap = embAMap;
}
public Map<XMLAssocOverEmbedB, XMLAssocOverEmbed> getEmbAMap() {
return embaMap;
}
public void setId(int id) {
this.id = id;
}

View File

@ -37,6 +37,21 @@
</association-override>
<collection-table name="XML_EMBALIST"/>
</element-collection>
<element-collection name="embaMap">
<association-override name="key.eb">
<join-column name="key_emba_entb" />
</association-override>
<association-override name="key.meb">
<join-column name="key_emba_mentb" />
</association-override>
<association-override name="value.eb">
<join-column name="value_emba_entb" />
</association-override>
<association-override name="value.meb">
<join-column name="value_emba_mentb" />
</association-override>
<collection-table name="XML_EMBAMAP_3"/>
</element-collection>
</attributes>
</entity>
@ -69,4 +84,21 @@
</one-to-one>
</attributes>
</embeddable>
<embeddable class="org.apache.openjpa.persistence.embed.attrOverrides.XMLAssocOverEmbedB">
<attributes>
<basic name="name"/>
<many-to-one name="meb">
<cascade>
<cascade-all />
</cascade>
</many-to-one>
<one-to-one name="eb">
<cascade>
<cascade-all />
</cascade>
</one-to-one>
</attributes>
</embeddable>
</entity-mappings>

View File

@ -23,6 +23,7 @@
<persistence-unit name="AssocOverPU">
<mapping-file>org/apache/openjpa/persistence/embed/embed-assoc-over-orm.xml</mapping-file>
<class>org.apache.openjpa.persistence.embed.attrOverrides.XMLAssocOverEmbed</class>
<class>org.apache.openjpa.persistence.embed.attrOverrides.XMLAssocOverEmbedB</class>
<class>org.apache.openjpa.persistence.embed.attrOverrides.XMLAssocOverEntityA</class>
<class>org.apache.openjpa.persistence.embed.attrOverrides.XMLAssocOverEntityB</class>
<properties>