From 4bf637f0747fcbba281b2ad2442475336cea8dfe Mon Sep 17 00:00:00 2001 From: "A. Abram White" Date: Tue, 27 Feb 2007 18:14:45 +0000 Subject: [PATCH] Improve error checks for mapped-by mappings. Mark deleted instances as eligible for state restore on rollback so they don't always clear. Always cascade attach to embedded instances. git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@512350 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/jdbc/meta/strats/RelationFieldStrategy.java | 2 +- .../meta/strats/RelationToManyInverseKeyFieldStrategy.java | 2 +- .../jdbc/meta/strats/RelationToManyTableFieldStrategy.java | 2 +- .../org/apache/openjpa/jdbc/meta/strats/localizer.properties | 2 +- .../main/java/org/apache/openjpa/kernel/PDeletedState.java | 4 ++++ .../main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java | 2 ++ 6 files changed, 10 insertions(+), 4 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java index e80afea8a..8b46adca3 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java @@ -86,7 +86,7 @@ public class RelationFieldStrategy field.getValueInfo().assertNoSchemaComponents(field, !adapt); mapped.resolve(mapped.MODE_META | mapped.MODE_MAPPING); - if (!mapped.getDefiningMapping().isMapped()) + if (!mapped.isMapped() || mapped.isSerialized()) throw new MetaDataException(_loc.get("mapped-by-unmapped", field, mapped)); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyInverseKeyFieldStrategy.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyInverseKeyFieldStrategy.java index 6dfa8474e..d6f70de75 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyInverseKeyFieldStrategy.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyInverseKeyFieldStrategy.java @@ -119,7 +119,7 @@ public abstract class RelationToManyInverseKeyFieldStrategy boolean criteria = vinfo.getUseClassCriteria(); if (mapped != null) { mapped.resolve(mapped.MODE_META | mapped.MODE_MAPPING); - if (!(mapped.getStrategy()instanceof RelationFieldStrategy)) + if (!(mapped.getStrategy() instanceof RelationFieldStrategy)) throw new MetaDataException(_loc.get("not-inv-relation", field, mapped)); vinfo.assertNoSchemaComponents(elem, !adapt); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyTableFieldStrategy.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyTableFieldStrategy.java index c845302fc..92ea16c47 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyTableFieldStrategy.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyTableFieldStrategy.java @@ -110,7 +110,7 @@ public abstract class RelationToManyTableFieldStrategy vinfo.assertNoSchemaComponents(elem, !adapt); mapped.resolve(mapped.MODE_META | mapped.MODE_MAPPING); - if (!mapped.getDefiningMapping().isMapped()) + if (!mapped.isMapped() || mapped.isSerialized()) throw new MetaDataException(_loc.get("mapped-by-unmapped", field, mapped)); diff --git a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/strats/localizer.properties b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/strats/localizer.properties index a1be227ff..09cdbe522 100644 --- a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/strats/localizer.properties +++ b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/strats/localizer.properties @@ -20,7 +20,7 @@ mapped-inverse-unjoined: Field "{0}" as defined in "{1}" cannot be mapped by \ "{2}". You cannot use an inverse foreign key to map a superclass field of \ an unjoined subclass. mapped-by-unmapped: Field "{0}" cannot be mapped by "{1}", because the related \ - type is unmapped. + field or type is unmapped. cant-join: Cannot join across "{0}". The related type has unjoined subclasses. cant-inverse: "{0}" is not a valid mapping. Inverse foreign key-based \ relations to types with unjoined subclasses are not supported. diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PDeletedState.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PDeletedState.java index 6f9f93748..f7c5c008a 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PDeletedState.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PDeletedState.java @@ -25,6 +25,10 @@ package org.apache.openjpa.kernel; class PDeletedState extends PCState { + void initialize(StateManagerImpl context) { + context.saveFields(false); + } + PCState flush(StateManagerImpl context) { return PDELETEDFLUSHED; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java index 218f9805a..03ed5a153 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java @@ -243,6 +243,8 @@ public class ValueMetaDataImpl if (_owner.getManagement() != FieldMetaData.MANAGE_PERSISTENT || !isDeclaredTypePC()) // attach acts on declared type return CASCADE_NONE; + if (isEmbeddedPC()) + return CASCADE_IMMEDIATE; return _attach; }