Author: smarlow(a)redhat.com
Date: 2010-01-06 12:01:04 -0500 (Wed, 06 Jan 2010)
New Revision: 18420
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/ops/OrderByTest.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/ops/Products.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/ops/Widgets.java
Log:
HHH-4688 Make sure @OrderBy works for @ElementCollection. added test case
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/ops/OrderByTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/ops/OrderByTest.java
(rev 0)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/ops/OrderByTest.java 2010-01-06
17:01:04 UTC (rev 18420)
@@ -0,0 +1,61 @@
+package org.hibernate.ejb.test.ops;
+
+import org.hibernate.ejb.test.TestCase;
+
+import javax.persistence.EntityManager;
+import java.util.HashSet;
+import java.util.Iterator;
+
+public class OrderByTest extends TestCase {
+
+ public Class[] getAnnotatedClasses() {
+ return new Class[]{
+ Products.class,
+ Widgets.class
+ };
+ }
+
+ /**
+ * Test @OrderBy on the Widgets.name field.
+ *
+ */
+ public void testOrderByName() throws Exception {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+
+ Products p = new Products();
+ HashSet<Widgets> set = new HashSet<Widgets>();
+
+ Widgets widget = new Widgets();
+ widget.setName("hammer");
+ set.add(widget);
+ em.persist(widget);
+
+ widget = new Widgets();
+ widget.setName("axel");
+ set.add(widget);
+ em.persist(widget);
+
+ widget = new Widgets();
+ widget.setName("screwdriver");
+ set.add(widget);
+ em.persist(widget);
+
+ p.setWidgets(set);
+ em.persist(p);
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ em.clear();
+ p = em.find(Products.class,p.getId());
+ assertTrue("has three Widgets", p.getWidgets().size() == 3);
+ Iterator iter = p.getWidgets().iterator();
+ assertEquals( "axel", ((Widgets)iter.next()).getName() );
+ assertEquals( "hammer", ((Widgets)iter.next()).getName() );
+ assertEquals( "screwdriver", ((Widgets)iter.next()).getName() );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+
+}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/ops/Products.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/ops/Products.java
(rev 0)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/ops/Products.java 2010-01-06
17:01:04 UTC (rev 18420)
@@ -0,0 +1,39 @@
+package org.hibernate.ejb.test.ops;
+
+import javax.persistence.ElementCollection;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OrderBy;
+
+import java.util.Set;
+
+@SuppressWarnings({"unchecked", "serial"})
+
+@Entity
+public class Products {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @ElementCollection
+ @OrderBy("name ASC")
+ private Set<Widgets> widgets;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Set<Widgets> getWidgets() {
+ return widgets;
+ }
+
+ public void setWidgets(Set<Widgets> widgets) {
+ this.widgets = widgets;
+ }
+
+}
\ No newline at end of file
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/ops/Widgets.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/ops/Widgets.java
(rev 0)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/ops/Widgets.java 2010-01-06
17:01:04 UTC (rev 18420)
@@ -0,0 +1,34 @@
+package org.hibernate.ejb.test.ops;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+public class Widgets {
+ private String name;
+ private int id;
+
+ public Widgets() {
+
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Id
+ @GeneratedValue
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+}
Show replies by date