HHH-4688 Make sure @OrderBy works for @ElementCollection. move test case
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18427 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
658df91a5e
commit
b24ea51873
|
@ -0,0 +1,63 @@
|
|||
package org.hibernate.test.annotations.collectionelement;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.test.annotations.TestCase;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class OrderByTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Test @OrderBy on the Widgets.name field.
|
||||
*
|
||||
*/
|
||||
public void testOrderByName() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
Products p = new Products();
|
||||
HashSet<Widgets> set = new HashSet<Widgets>();
|
||||
|
||||
Widgets widget = new Widgets();
|
||||
widget.setName("hammer");
|
||||
set.add(widget);
|
||||
s.persist(widget);
|
||||
|
||||
widget = new Widgets();
|
||||
widget.setName("axel");
|
||||
set.add(widget);
|
||||
s.persist(widget);
|
||||
|
||||
widget = new Widgets();
|
||||
widget.setName("screwdriver");
|
||||
set.add(widget);
|
||||
s.persist(widget);
|
||||
|
||||
p.setWidgets(set);
|
||||
s.persist(p);
|
||||
tx.commit();
|
||||
|
||||
tx = s.beginTransaction();
|
||||
s.clear();
|
||||
p = (Products) s.get(Products.class,p.getId());
|
||||
Assert.assertTrue("has three Widgets", p.getWidgets().size() == 3);
|
||||
Iterator iter = p.getWidgets().iterator();
|
||||
Assert.assertEquals( "axel", ((Widgets)iter.next()).getName() );
|
||||
Assert.assertEquals( "hammer", ((Widgets)iter.next()).getName() );
|
||||
Assert.assertEquals( "screwdriver", ((Widgets)iter.next()).getName() );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
protected Class[] getMappings() {
|
||||
return new Class[] {
|
||||
Products.class,
|
||||
Widgets.class
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.ejb.test.ops;
|
||||
package org.hibernate.test.annotations.collectionelement;
|
||||
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.ejb.test.ops;
|
||||
package org.hibernate.test.annotations.collectionelement;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
|
@ -1,61 +0,0 @@
|
|||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue