From b5bab78e043329c97b0ddac1558bd595e5a522aa Mon Sep 17 00:00:00 2001 From: Patrick Linskey Date: Sat, 10 Mar 2007 11:14:44 +0000 Subject: [PATCH] OPENJPA-142: read entity names specified in XML. Also added comment clarifying that ClassMetaData.setTypeAlias() is only used at enhance time. git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@516682 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/openjpa/meta/ClassMetaData.java | 3 +- .../persistence/xml/SimpleXmlEntity.java | 16 ++++++ .../persistence/xml/TestSimpleXmlEntity.java | 55 +++++++++++++++++++ .../test/resources/META-INF/persistence.xml | 7 +++ .../apache/openjpa/persistence/xml/orm.xml | 23 ++++++++ .../XMLPersistenceMetaDataParser.java | 10 +++- 6 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/SimpleXmlEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSimpleXmlEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java index 4796d2a3e..33777e524 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java @@ -588,7 +588,8 @@ public class ClassMetaData /** * Sets the alias for the described type. The alias can be * any arbitrary string that the implementation can later use to - * refer to the class. + * refer to the class. Note that at runtime, only the alias + * computed when the persistent type was enhanced is used. * * @param alias the alias name to apply to the described type */ diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/SimpleXmlEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/SimpleXmlEntity.java new file mode 100644 index 000000000..f54c3be2e --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/SimpleXmlEntity.java @@ -0,0 +1,16 @@ +package org.apache.openjpa.persistence.xml; + +public class SimpleXmlEntity { + + private long id; + private int version; + private String stringField; + + public String getStringField() { + return stringField; + } + + public void setStringField(String stringField) { + this.stringField = stringField; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSimpleXmlEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSimpleXmlEntity.java new file mode 100644 index 000000000..550f7529d --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSimpleXmlEntity.java @@ -0,0 +1,55 @@ +package org.apache.openjpa.persistence.xml; + +import java.util.Map; +import javax.persistence.EntityManager; + +import org.apache.openjpa.persistence.test.SingleEMTest; +import org.apache.openjpa.persistence.ArgumentException; + +public class TestSimpleXmlEntity + extends SingleEMTest { + + public TestSimpleXmlEntity() { + super(SimpleXmlEntity.class); + } + + protected void setEMFProps(Map props) { + super.setEMFProps(props); + } + + public void testNamedQueryInXmlNamedEntity() { + EntityManager em = emf.createEntityManager(); + em.createNamedQuery("SimpleXml.findAll").getResultList(); + em.close(); + } + + public void testNamedQueryInXmlUsingShortClassName() { + EntityManager em = emf.createEntityManager(); + try { + em.createNamedQuery("SimpleXmlEntity.findAll").getResultList(); + fail("should not be able to execute query using short class name " + + "for entity that has an entity name specified"); + } catch (ArgumentException ae) { + // expected + } + em.close(); + } + + public void testNamedEntityInDynamicQuery() { + EntityManager em = emf.createEntityManager(); + em.createQuery("select o from SimpleXml o").getResultList(); + em.close(); + } + + public void testShortClassNameInDynamicQuery() { + EntityManager em = emf.createEntityManager(); + try { + em.createQuery("select o from SimpleXmlEntity o").getResultList(); + fail("should not be able to execute query using short class name " + + "for entity that has an entity name specified"); + } catch (ArgumentException ae) { + // expected + } + em.close(); + } +} diff --git a/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml b/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml index 77b741173..12aa980d6 100644 --- a/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml +++ b/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml @@ -24,6 +24,13 @@ org.apache.openjpa.persistence.PersistenceProviderImpl --> + + org/apache/openjpa/persistence/xml/orm.xml