Author: hardy.ferentschik
Date: 2008-06-23 04:23:48 -0400 (Mon, 23 Jun 2008)
New Revision: 14797
Added:
search/trunk/src/test/org/hibernate/search/test/embedded/State.java
Modified:
search/trunk/doc/reference/en/modules/mapping.xml
search/trunk/src/test/org/hibernate/search/test/embedded/Author.java
search/trunk/src/test/org/hibernate/search/test/embedded/Country.java
search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java
search/trunk/src/test/org/hibernate/search/test/embedded/Person.java
search/trunk/src/test/org/hibernate/search/test/embedded/Tower.java
Log:
* Added another test for @IndexedEmbedded
* Import cleanup
* Updated documtation - also OneToMany can be annotated with @indexedEmbedded
Modified: search/trunk/doc/reference/en/modules/mapping.xml
===================================================================
--- search/trunk/doc/reference/en/modules/mapping.xml 2008-06-22 23:18:11 UTC (rev 14796)
+++ search/trunk/doc/reference/en/modules/mapping.xml 2008-06-23 08:23:48 UTC (rev 14797)
@@ -349,7 +349,7 @@
...
}</programlisting>
- <para>Any <literal>@ManyToMany, @*ToOne</literal> and
+ <para>Any <literal>@*ToMany, @*ToOne</literal> and
<literal>@Embedded</literal> attribute can be annotated with
<literal>@IndexedEmbedded</literal>. The attributes of the associated
class will then be added to the main entity index. In the previous
Modified: search/trunk/src/test/org/hibernate/search/test/embedded/Author.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/Author.java 2008-06-22
23:18:11 UTC (rev 14796)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/Author.java 2008-06-23
08:23:48 UTC (rev 14797)
@@ -5,7 +5,6 @@
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
-import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.DocumentId;
Modified: search/trunk/src/test/org/hibernate/search/test/embedded/Country.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/Country.java 2008-06-22
23:18:11 UTC (rev 14796)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/Country.java 2008-06-23
08:23:48 UTC (rev 14797)
@@ -1,13 +1,21 @@
-//$
+// $Id:$
package org.hibernate.search.test.embedded;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import org.hibernate.annotations.Cascade;
+import org.hibernate.annotations.IndexColumn;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
/**
* @author Emmanuel Bernard
@@ -19,9 +27,16 @@
@GeneratedValue
@DocumentId
private Integer id;
+
@Field
private String name;
+ @OneToMany(fetch = FetchType.LAZY)
+ @IndexColumn(name = "list_position")
+ @Cascade(org.hibernate.annotations.CascadeType.ALL)
+ @IndexedEmbedded
+ private List<State> states = new ArrayList<State>();
+
public Integer getId() {
return id;
}
@@ -37,4 +52,12 @@
public void setName(String name) {
this.name = name;
}
+
+ public List<State> getStates() {
+ return states;
+ }
+
+ public void setStates(List<State> states) {
+ this.states = states;
+ }
}
Property changes on:
search/trunk/src/test/org/hibernate/search/test/embedded/Country.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java 2008-06-22
23:18:11 UTC (rev 14796)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java 2008-06-23
08:23:48 UTC (rev 14797)
@@ -1,6 +1,7 @@
//$Id$
package org.hibernate.search.test.embedded;
+import java.util.ArrayList;
import java.util.List;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
@@ -22,6 +23,7 @@
/**
* @author Emmanuel Bernard
*/
+@SuppressWarnings("unchecked")
public class EmbeddedTest extends SearchTestCase {
public void testEmbeddedIndexing() throws Exception {
@@ -91,7 +93,39 @@
s.close();
}
+
+ public void testEmbeddedIndexingOneToMany() throws Exception {
+ Country country = new Country();
+ country.setName("Germany");
+ List states = new ArrayList<State>();
+ State bayern = new State();
+ bayern.setName("Bayern");
+ State hessen = new State();
+ hessen.setName("Hessen");
+ State sachsen = new State();
+ sachsen.setName("Sachsen");
+ states.add(bayern);
+ states.add(hessen);
+ states.add(sachsen);
+ country.setStates(states);
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ s.persist( country );
+ tx.commit();
+
+
+ FullTextSession session = Search.createFullTextSession( s );
+ QueryParser parser = new QueryParser( "id", new StandardAnalyzer() );
+ Query query;
+ List result;
+
+ query = parser.parse( "states.name:Hessen" );
+ result = session.createFullTextQuery( query ).list();
+ assertEquals( "unable to find property in embedded", 1, result.size() );
+ s.close();
+ }
+
public void testContainedIn() throws Exception {
Tower tower = new Tower();
tower.setName( "JBoss tower" );
@@ -251,7 +285,8 @@
Product.class,
Order.class,
Author.class,
- Country.class
+ Country.class,
+ State.class
};
}
}
Modified: search/trunk/src/test/org/hibernate/search/test/embedded/Person.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/Person.java 2008-06-22
23:18:11 UTC (rev 14796)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/Person.java 2008-06-23
08:23:48 UTC (rev 14797)
@@ -1,4 +1,4 @@
-//$
+// $Id:$
package org.hibernate.search.test.embedded;
/**
Property changes on: search/trunk/src/test/org/hibernate/search/test/embedded/Person.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: search/trunk/src/test/org/hibernate/search/test/embedded/State.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/State.java
(rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/State.java 2008-06-23
08:23:48 UTC (rev 14797)
@@ -0,0 +1,37 @@
+// $Id:$
+package org.hibernate.search.test.embedded;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.search.annotations.Field;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class State {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Field
+ private String name;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Property changes on: search/trunk/src/test/org/hibernate/search/test/embedded/State.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: search/trunk/src/test/org/hibernate/search/test/embedded/Tower.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/Tower.java 2008-06-22
23:18:11 UTC (rev 14796)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/Tower.java 2008-06-23
08:23:48 UTC (rev 14797)
@@ -5,7 +5,6 @@
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
-import javax.persistence.OneToOne;
import javax.persistence.ManyToOne;
import org.hibernate.search.annotations.DocumentId;
Show replies by date