[hibernate-commits] Hibernate SVN: r12777 - in trunk/HibernateExt/annotations/src: test/org/hibernate/test/annotations/collectionelement and 1 other directory.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Tue Jul 17 09:56:01 EDT 2007
Author: epbernard
Date: 2007-07-17 09:56:01 -0400 (Tue, 17 Jul 2007)
New Revision: 12777
Added:
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/collectionelement/LocalizedString.java
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/collectionelement/TestCourse.java
Modified:
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java
Log:
ANN-634 @CollectionOfElements clashes with @Fetch JOIN and @Filter or @Where
Modified: trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
--- trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2007-07-17 13:24:55 UTC (rev 12776)
+++ trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2007-07-17 13:56:01 UTC (rev 12777)
@@ -1251,6 +1251,7 @@
//for now it can't happen, but sometime soon...
if ( ( collValue.getFilterMap().size() != 0 || StringHelper.isNotEmpty( collValue.getWhere() ) ) &&
collValue.getFetchMode() == FetchMode.JOIN &&
+ ! (collValue.getElement() instanceof SimpleValue) && //SimpleValue (CollectionOfElements) are always SELECT but it does not matter
collValue.getElement().getFetchMode() != FetchMode.JOIN ) {
throw new MappingException(
"@ManyToMany or @CollectionOfElements defining filter or where without join fetching "
Modified: trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java
===================================================================
--- trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java 2007-07-17 13:24:55 UTC (rev 12776)
+++ trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java 2007-07-17 13:56:01 UTC (rev 12777)
@@ -1,8 +1,12 @@
//$Id$
package org.hibernate.test.annotations.collectionelement;
+import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
+import org.hibernate.Filter;
+import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.test.annotations.Country;
@@ -29,7 +33,7 @@
boy.getScorePerNickName().put( "Johnny", new Integer( 3 ) );
boy.getScorePerNickName().put( "Thing", new Integer( 5 ) );
int[] favNbrs = new int[4];
- for ( int index = 0; index < favNbrs.length - 1; index++ ) {
+ for (int index = 0; index < favNbrs.length - 1; index++) {
favNbrs[index] = index * 3;
}
boy.setFavoriteNumbers( favNbrs );
@@ -127,7 +131,7 @@
boy.getScorePerNickName().put( "Johnny", new Integer( 3 ) );
boy.getScorePerNickName().put( "Thing", new Integer( 5 ) );
int[] favNbrs = new int[4];
- for ( int index = 0; index < favNbrs.length - 1; index++ ) {
+ for (int index = 0; index < favNbrs.length - 1; index++) {
favNbrs[index] = index * 3;
}
boy.setFavoriteNumbers( favNbrs );
@@ -154,11 +158,42 @@
s.close();
}
+ public void testFetchEagerAndFilter() throws Exception {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ TestCourse test = new TestCourse();
+
+ LocalizedString title = new LocalizedString( "title in english" );
+ title.getVariations().put( Locale.FRENCH.getLanguage(), "title en francais" );
+ test.setTitle( title );
+ s.save( test );
+
+ s.flush();
+ s.clear();
+
+ Filter filter = s.enableFilter( "selectedLocale" );
+ filter.setParameter( "param", "fr" );
+
+ Query q = s.createQuery( "from TestCourse t" );
+ List l = q.list();
+ assertEquals( 1, l.size() );
+
+ TestCourse t = (TestCourse) s.get( TestCourse.class, test.getTestCourseId() );
+ Iterator it = t.getTitle().getVariations().values().iterator();
+ assertEquals( 1, t.getTitle().getVariations().size() );
+
+ tx.rollback();
+
+ s.close();
+ }
+
+
protected Class[] getMappings() {
- return new Class[]{
+ return new Class[] {
Boy.class,
- Country.class
+ Country.class,
+ TestCourse.class
};
}
}
Added: trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/collectionelement/LocalizedString.java
===================================================================
--- trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/collectionelement/LocalizedString.java (rev 0)
+++ trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/collectionelement/LocalizedString.java 2007-07-17 13:56:01 UTC (rev 12777)
@@ -0,0 +1,47 @@
+//$Id$
+package org.hibernate.test.annotations.collectionelement;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Locale;
+import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+
+import org.hibernate.annotations.CollectionOfElements;
+import org.hibernate.annotations.Fetch;
+import org.hibernate.annotations.MapKey;
+import org.hibernate.annotations.FetchMode;
+import org.hibernate.annotations.Filter;
+
+/**
+ * @author Emmanuel Bernard
+ */
+ at Embeddable
+public class LocalizedString implements Serializable {
+
+ private static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
+
+ public LocalizedString() {
+ }
+
+ public LocalizedString(String string) {
+ this.getVariations().put( DEFAULT_LOCALE.getLanguage(), string );
+ }
+
+ private Map<String, String> variations =
+ new HashMap<String, String>( 1 );
+
+ @CollectionOfElements
+ @MapKey( columns = @Column( name = "language_code" ) )
+ @Fetch( FetchMode.JOIN )
+ @Filter( name = "selectedLocale",
+ condition = " language_code = :param " )
+ public Map<String, String> getVariations() {
+ return variations;
+ }
+
+ public void setVariations(Map<String, String> variations) {
+ this.variations = variations;
+ }
+}
Added: trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/collectionelement/TestCourse.java
===================================================================
--- trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/collectionelement/TestCourse.java (rev 0)
+++ trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/collectionelement/TestCourse.java 2007-07-17 13:56:01 UTC (rev 12777)
@@ -0,0 +1,43 @@
+//$Id$
+package org.hibernate.test.annotations.collectionelement;
+
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Embedded;
+import javax.persistence.GenerationType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+
+import org.hibernate.annotations.ParamDef;
+import org.hibernate.annotations.FilterDef;
+
+/**
+ * @author Emmanuel Bernard
+ */
+ at Entity
+ at FilterDef(name="selectedLocale", parameters={ @ParamDef( name="param", type="string" ) } )
+public class TestCourse {
+
+ private Long testCourseId;
+
+ private LocalizedString title;
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ public Long getTestCourseId() {
+ return testCourseId;
+ }
+
+ public void setTestCourseId(Long testCourseId) {
+ this.testCourseId = testCourseId;
+ }
+
+ @Embedded
+ public LocalizedString getTitle() {
+ return title;
+ }
+
+ public void setTitle(LocalizedString title) {
+ this.title = title;
+ }
+}
\ No newline at end of file
More information about the hibernate-commits
mailing list