From 670d59ef0f54aa196308d6114dc7a0b2eff28e4f Mon Sep 17 00:00:00 2001 From: Fay Wang Date: Sun, 4 Apr 2010 17:28:52 +0000 Subject: [PATCH] OPENJPA-1611: fix EMBEDDED attr type git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@930721 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/persistence/meta/TestMetamodel.java | 12 +++++++++++- .../org/apache/openjpa/persistence/meta/Members.java | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetamodel.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetamodel.java index 15ad085e9..667c8f22d 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetamodel.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetamodel.java @@ -38,6 +38,8 @@ import javax.persistence.metamodel.PluralAttribute.CollectionType; import javax.persistence.metamodel.Type.PersistenceType; import org.apache.openjpa.meta.ClassMetaData; +import org.apache.openjpa.persistence.embed.Address; +import org.apache.openjpa.persistence.embed.Geocode; import org.apache.openjpa.persistence.enhance.identity.Book; import org.apache.openjpa.persistence.enhance.identity.BookId; import org.apache.openjpa.persistence.enhance.identity.Library; @@ -71,7 +73,9 @@ public class TestMetamodel extends SingleEMFTestCase { OneOneChild.class, Book.class, Library.class, - Page.class); + Page.class, + Address.class, + Geocode.class); emf.createEntityManager(); model = (MetamodelImpl)emf.getMetamodel(); } @@ -313,6 +317,12 @@ public class TestMetamodel extends SingleEMFTestCase { assertEquals(PersistentAttributeType.BASIC, pInt.getPersistentAttributeType()); } + public void testEmbeddedAttributeType() { + ManagedType
type = model.entity(Address.class); + Attribute.PersistentAttributeType attr = type.getAttribute("geocode").getPersistentAttributeType(); + assertEquals(PersistentAttributeType.EMBEDDED, attr); + } + public void testNotFoundErrorMessage() { IdentifiableType e0 = model.entity(ImplicitFieldAccessBase.class); String name = "unknown"; diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/Members.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/Members.java index b2648204e..5f7431e51 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/Members.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/Members.java @@ -200,6 +200,10 @@ public class Members { public final PersistentAttributeType getPersistentAttributeType() { if (!fmd.isDeclaredTypePC()) return super.getPersistentAttributeType(); + if (fmd.getValue().isEmbedded() && fmd.getAssociationType() == 0) { + return PersistentAttributeType.EMBEDDED; + } + return fmd.getMappedByMetaData() == null || !fmd.getType().isAssignableFrom(Collection.class) ? PersistentAttributeType.ONE_TO_ONE : PersistentAttributeType.ONE_TO_MANY;