Author: epbernard
Date: 2006-11-30 14:57:18 -0500 (Thu, 30 Nov 2006)
New Revision: 10898
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/GroupWithSet.java
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/Collection.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
Log:
HHH-2274 use ordered collection when manyToManyOrderBy is used
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/Collection.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/Collection.java 2006-11-30
19:56:14 UTC (rev 10897)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/Collection.java 2006-11-30
19:57:18 UTC (rev 10898)
@@ -599,7 +599,7 @@
}
public boolean hasOrder() {
- return orderBy!=null;
+ return orderBy!=null || manyToManyOrderBy!=null;
}
public void setComparatorClassName(String comparatorClassName) {
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/GroupWithSet.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/GroupWithSet.java 2006-11-30
19:56:14 UTC (rev 10897)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/GroupWithSet.java 2006-11-30
19:57:18 UTC (rev 10898)
@@ -0,0 +1,60 @@
+//$Id$
+package org.hibernate.test.annotations.manytomany;
+
+import java.util.Collection;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.OrderBy;
+import javax.persistence.Table;
+import javax.persistence.UniqueConstraint;
+
+import org.hibernate.annotations.Where;
+import org.hibernate.annotations.FilterDef;
+import org.hibernate.annotations.Filter;
+import org.hibernate.annotations.FilterJoinTable;
+import org.hibernate.annotations.WhereJoinTable;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Table(name = "tbl_group")
+@FilterDef(name="Groupfilter")
+public class GroupWithSet {
+ private Integer id;
+ private Set<Permission> permissions;
+
+ @Id
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ @ManyToMany(cascade = CascadeType.PERSIST)
+ @JoinTable(name = "GROUPS_PERMISSIONS",
+ uniqueConstraints = @UniqueConstraint(columnNames = {"group_id",
"permission"}),
+ joinColumns = @JoinColumn(name = "group_id", referencedColumnName =
"id"),
+ inverseJoinColumns = @JoinColumn(name = "permission", referencedColumnName =
"permission")
+ )
+ @OrderBy("expirationDate")
+ @Where(clause = "1=1")
+ @WhereJoinTable(clause = "2=2")
+ @Filter(name="Groupfilter", condition = "3=3")
+ @FilterJoinTable(name="Groupfilter", condition = "4=4")
+ public Set<Permission> getPermissions() {
+ return permissions;
+ }
+
+ public void setPermissions(Set<Permission> permissions) {
+ this.permissions = permissions;
+ }
+}
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2006-11-30
19:56:14 UTC (rev 10897)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2006-11-30
19:57:18 UTC (rev 10898)
@@ -465,6 +465,45 @@
s.close();
}
+ public void testAssociationTableAndOrderByWithSet() throws Exception {
+ Session s = openSession();
+ s.enableFilter( "Groupfilter" );
+
+ Permission readAccess = new Permission();
+ readAccess.setPermission( "read" );
+ readAccess.setExpirationDate( new Date() );
+
+ Permission writeAccess = new Permission();
+ writeAccess.setPermission( "write" );
+ writeAccess.setExpirationDate( new Date( new Date().getTime() - 10*60*1000 ) );
+
+ Permission executeAccess = new Permission();
+ executeAccess.setPermission( "execute" );
+ executeAccess.setExpirationDate( new Date( new Date().getTime() - 5*60*1000 ) );
+
+ Set<Permission> coll = new HashSet<Permission>( 3 );
+ coll.add( readAccess );
+ coll.add( writeAccess );
+ coll.add( executeAccess );
+
+ GroupWithSet group = new GroupWithSet();
+ group.setId( new Integer( 1 ) );
+ group.setPermissions( coll );
+ s.getTransaction().begin();
+ s.persist( group );
+ s.flush();
+ s.clear();
+
+ group = (GroupWithSet) s.get( GroupWithSet.class, group.getId() );
+ s.createQuery( "select g from Group g join fetch g.permissions").list();
+ Iterator<Permission> permIter = group.getPermissions().iterator();
+ assertEquals( "write", permIter.next().getPermission() );
+ assertEquals( "execute", permIter.next().getPermission() );
+ assertEquals( "read", permIter.next().getPermission() );
+ s.getTransaction().rollback();
+ s.close();
+ }
+
public void testJoinedSubclassManyToMany() throws Exception {
Session s = openSession();
Zone a = new Zone();
@@ -544,6 +583,7 @@
City.class,
Cat.class,
Group.class,
+ GroupWithSet.class,
Permission.class,
Zone.class,
Inspector.class,