mirror of https://github.com/apache/openjpa.git
OPENJPA-157. Fix to use the getIndependentTypeMappings to handle the case of field's declared type being abstract/unmapped
git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@509885 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0b8bf2818c
commit
82a62a6b78
|
@ -31,6 +31,7 @@ import org.apache.openjpa.kernel.StoreContext;
|
||||||
import org.apache.openjpa.lib.util.Localizer;
|
import org.apache.openjpa.lib.util.Localizer;
|
||||||
import org.apache.openjpa.meta.JavaTypes;
|
import org.apache.openjpa.meta.JavaTypes;
|
||||||
import org.apache.openjpa.util.MetaDataException;
|
import org.apache.openjpa.util.MetaDataException;
|
||||||
|
import org.apache.openjpa.util.UserException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper methods for relation mappings.
|
* Helper methods for relation mappings.
|
||||||
|
@ -74,12 +75,19 @@ public class RelationStrategies {
|
||||||
public static Object toDataStoreValue(ValueMapping vm, Object val,
|
public static Object toDataStoreValue(ValueMapping vm, Object val,
|
||||||
JDBCStore store) {
|
JDBCStore store) {
|
||||||
ClassMapping rel;
|
ClassMapping rel;
|
||||||
if (val == null || val.getClass() == vm.getType())
|
if (val == null) {
|
||||||
|
ClassMapping[] clss = vm.getIndependentTypeMappings();
|
||||||
|
rel = (clss.length > 0) ? clss[0] : vm.getTypeMapping();
|
||||||
|
} else if (val.getClass() == vm.getType())
|
||||||
rel = vm.getTypeMapping(); // common case
|
rel = vm.getTypeMapping(); // common case
|
||||||
else
|
else
|
||||||
rel = vm.getMappingRepository().getMapping(val.getClass(),
|
rel = vm.getMappingRepository().getMapping(val.getClass(),
|
||||||
store.getContext().getClassLoader(), true);
|
store.getContext().getClassLoader(), true);
|
||||||
|
|
||||||
|
if (!rel.isMapped())
|
||||||
|
throw new UserException(_loc.get("unmapped-datastore-value",
|
||||||
|
rel.getDescribedType()));
|
||||||
|
|
||||||
Column[] cols;
|
Column[] cols;
|
||||||
if (vm.getJoinDirection() == ValueMapping.JOIN_INVERSE)
|
if (vm.getJoinDirection() == ValueMapping.JOIN_INVERSE)
|
||||||
cols = rel.getPrimaryKeyColumns();
|
cols = rel.getPrimaryKeyColumns();
|
||||||
|
|
|
@ -131,3 +131,5 @@ unknown-discrim-value: Could not map disciminator value "{0}" to any \
|
||||||
bad-unmapped-rel: "{0}" cannot be mapped without stringifying the oid of \
|
bad-unmapped-rel: "{0}" cannot be mapped without stringifying the oid of \
|
||||||
the related object to a string column. The related type is unmapped and \
|
the related object to a string column. The related type is unmapped and \
|
||||||
its "{1}" primary key field does not use a simple mapping.
|
its "{1}" primary key field does not use a simple mapping.
|
||||||
|
unmapped-datastore-value: Instances of type "{0}" are not valid query \
|
||||||
|
parameters because the type is not mapped.
|
Loading…
Reference in New Issue