Author: epbernard
Date: 2007-12-07 23:22:44 -0500 (Fri, 07 Dec 2007)
New Revision: 14238
Added:
search/trunk/src/test/org/hibernate/search/test/embedded/Country.java
Modified:
search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
search/trunk/src/test/org/hibernate/search/test/embedded/Address.java
search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java
Log:
HSEARCH-140 integer overflow break index embedded after level 1
Modified: search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2007-12-07
22:47:01 UTC (rev 14237)
+++ search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2007-12-08
04:22:44 UTC (rev 14238)
@@ -233,7 +233,11 @@
IndexedEmbedded embeddedAnn = member.getAnnotation( IndexedEmbedded.class );
if ( embeddedAnn != null ) {
int oldMaxLevel = maxLevel;
- maxLevel = embeddedAnn.depth() + level > maxLevel ? maxLevel : embeddedAnn.depth()
+ level;
+ int potentialLevel = embeddedAnn.depth() + level;
+ if ( potentialLevel < 0 ) {
+ potentialLevel = Integer.MAX_VALUE;
+ }
+ maxLevel = potentialLevel > maxLevel ? maxLevel : potentialLevel;
level++;
XClass elementClass = member.getElementClass();
Modified: search/trunk/src/test/org/hibernate/search/test/embedded/Address.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/Address.java 2007-12-07
22:47:01 UTC (rev 14237)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/Address.java 2007-12-08
04:22:44 UTC (rev 14238)
@@ -1,20 +1,21 @@
//$Id$
package org.hibernate.search.test.embedded;
+import java.util.HashSet;
import java.util.Set;
-import java.util.HashSet;
import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
import javax.persistence.Id;
-import javax.persistence.GeneratedValue;
-import javax.persistence.OneToOne;
+import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
+import javax.persistence.CascadeType;
-import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.ContainedIn;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;
-import org.hibernate.search.annotations.ContainedIn;
/**
* @author Emmanuel Bernard
@@ -38,7 +39,19 @@
@ContainedIn
private Set<Tower> towers = new HashSet<Tower>();
+ public Country getCountry() {
+ return country;
+ }
+ public void setCountry(Country country) {
+ this.country = country;
+ }
+
+ @ManyToOne(cascade = { CascadeType.PERSIST })
+ @IndexedEmbedded
+ private Country country;
+
+
public Long getId() {
return id;
}
Added: search/trunk/src/test/org/hibernate/search/test/embedded/Country.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/Country.java
(rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/Country.java 2007-12-08
04:22:44 UTC (rev 14238)
@@ -0,0 +1,40 @@
+//$
+package org.hibernate.search.test.embedded;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Indexed;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Indexed
+public class Country {
+ @Id
+ @GeneratedValue
+ @DocumentId
+ 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;
+ }
+}
Modified: search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java 2007-12-07
22:47:01 UTC (rev 14237)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java 2007-12-08
04:22:44 UTC (rev 14238)
@@ -31,6 +31,9 @@
o.setName( "Atlanta Renting corp" );
a.setOwnedBy( o );
o.setAddress( a );
+ Country c = new Country();
+ c.setName( "France" );
+ a.setCountry( c );
Session s = openSession();
Transaction tx = s.beginTransaction();
@@ -55,6 +58,10 @@
result = session.createFullTextQuery( query, Tower.class ).list();
assertEquals( "unable to find property by id of embedded", 1, result.size()
);
+ query = parser.parse( "address.country.name:" + a.getCountry().getName() );
+ result = session.createFullTextQuery( query, Tower.class ).list();
+ assertEquals( "unable to find property with 2 levels of embedded", 1,
result.size() );
+
s.clear();
tx = s.beginTransaction();
@@ -230,7 +237,8 @@
Address.class,
Product.class,
Order.class,
- Author.class
+ Author.class,
+ Country.class
};
}
}