diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/Person.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/Person.java index e67fcc01f..aebe8c0b9 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/Person.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/Person.java @@ -1,3 +1,21 @@ +/* + * 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; import java.util.ArrayList; @@ -20,6 +38,22 @@ public class Person { @OrderBy("zipcode.zip, zipcode.plusFour") protected List
residences = new ArrayList
(); + @ElementCollection + @OrderBy("DESC") + private List nickNames = new ArrayList(); + + public List getNickNames() { + return nickNames; + } + + public void setNickNames(List nickNames) { + this.nickNames = nickNames; + } + + public void addNickName(String nickName) { + nickNames.add(nickName); + } + public String getSsn() { return ssn; } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/TestAttrOverrides.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/TestAttrOverrides.java index f04dd0753..9f456c799 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/TestAttrOverrides.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/TestAttrOverrides.java @@ -249,6 +249,7 @@ public class TestAttrOverrides extends SQLListenerTestCase { zipCode.setPlusFour("plusFour_" + id + "_" + i); addr.setZipcode(zipCode); p.addResidence(addr); + p.addNickName("nickName_ + " + i); } em.persist(p); return p; @@ -271,5 +272,14 @@ public class TestAttrOverrides extends SQLListenerTestCase { assertEquals(expPlusFour, plusFour); i++; } + + List nickNames = p.getNickNames(); + assertEquals(4, nickNames.size()); + i = 4; + for (String s : nickNames) { + String expNickName = "nickName_ + " + i; + assertEquals(expNickName, s); + i--; + } } } \ No newline at end of file diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java index 6c9eb03fd..a79489b60 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java @@ -1542,8 +1542,18 @@ public class AnnotationPersistenceMetaDataParser */ private void parseOrderBy(FieldMetaData fmd, OrderBy anno) { String dec = anno.value(); - if (dec.length() == 0) + if (fmd.isElementCollection() && + fmd.getElement().getEmbeddedMetaData() != null) { + if (dec.length() == 0 || dec.equals("ASC") || + dec.equals("DESC")) + throw new MetaDataException(_loc.get( + "invalid-orderBy", fmd)); + } + if (dec.length() == 0 || dec.equals("ASC")) dec = Order.ELEMENT + " asc"; + else if (dec.equals("DESC")) + dec = Order.ELEMENT + " desc"; + fmd.setOrderDeclaration(dec); } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java index 718901355..385557861 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java @@ -72,6 +72,8 @@ import org.apache.openjpa.meta.ValueMetaData; import static org.apache.openjpa.persistence.MetaDataTag.*; import static org.apache.openjpa.persistence.PersistenceStrategy.*; import org.apache.openjpa.util.ImplHelper; +import org.apache.openjpa.util.MetaDataException; + import serp.util.Numbers; /** @@ -1549,8 +1551,18 @@ public class XMLPersistenceMetaDataParser throws SAXException { FieldMetaData fmd = (FieldMetaData) currentElement(); String dec = currentText(); - if (StringUtils.isEmpty(dec)) + if (fmd.isElementCollection() && + fmd.getElement().getEmbeddedMetaData() != null) { + if (dec.length() == 0 || dec.equals("ASC") || + dec.equals("DESC")) + throw new MetaDataException(_loc.get( + "invalid-orderBy", fmd)); + } + if (StringUtils.isEmpty(dec) || dec.equals("ASC")) dec = Order.ELEMENT + " asc"; + else if (dec.equals("DESC")) + dec = Order.ELEMENT + " desc"; + fmd.setOrderDeclaration(dec); } diff --git a/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties b/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties index 19e34634f..c16c1b761 100644 --- a/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties +++ b/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties @@ -190,4 +190,6 @@ bad-lock-level: Invalid lock mode/level. Valid values are \ access-invalid: "{0}" is not a valid access style. Valid access styles are \ "PROPERTY" and "FIELD". getter-unmatched: Getter method "{0}" has no matching setter method. - \ No newline at end of file +invalid-orderBy: This is not a valid OrderBy annotation. The property or \ + field_name must be specified in the orederBy item of the orderBy list \ + for "{0}". \ No newline at end of file