Author: sannegrinovero
Date: 2009-09-27 08:49:54 -0400 (Sun, 27 Sep 2009)
New Revision: 17550
Added:
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Address.java
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Attribute.java
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/AttributeValue.java
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/NestedEmbeddedTest.java
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Person.java
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Place.java
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Product.java
Modified:
search/branches/Branch_3_1/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java
Log:
porting HSEARCH-391 from trunk to branch 3.1
Modified:
search/branches/Branch_3_1/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java
===================================================================
---
search/branches/Branch_3_1/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java 2009-09-25
13:23:40 UTC (rev 17549)
+++
search/branches/Branch_3_1/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java 2009-09-27
12:49:54 UTC (rev 17550)
@@ -574,62 +574,79 @@
}
if ( member.isArray() ) {
- for ( Object arrayValue : ( Object[] ) value ) {
- //highly inneficient but safe wrt the actual targeted class
- Class<?> valueClass = Hibernate.getClass( arrayValue );
- DocumentBuilderIndexedEntity<?> builderIndexedEntity =
searchFactoryImplementor.getDocumentBuilderIndexedEntity(
- valueClass
- );
- if ( builderIndexedEntity == null ) {
- continue;
- }
- processContainedInValue(
- arrayValue, queue, valueClass,
- builderIndexedEntity, searchFactoryImplementor
- );
+ @SuppressWarnings("unchecked")
+ T[] array = ( T[] ) value;
+ for ( T arrayValue : array ) {
+ processSingleContainedInInstance( queue, searchFactoryImplementor, arrayValue );
}
}
else if ( member.isCollection() ) {
- Collection collection;
- if ( Map.class.equals( member.getCollectionClass() ) ) {
- //hum
- collection = ( ( Map ) value ).values();
+ Collection<T> collection = getActualCollection( member, value );
+ for ( T collectionValue : collection ) {
+ processSingleContainedInInstance( queue, searchFactoryImplementor, collectionValue
);
}
- else {
- collection = ( Collection ) value;
- }
- for ( Object collectionValue : collection ) {
- //highly inneficient but safe wrt the actual targeted class
- Class<?> valueClass = Hibernate.getClass( collectionValue );
- DocumentBuilderIndexedEntity<?> builderIndexedEntity =
searchFactoryImplementor.getDocumentBuilderIndexedEntity(
- valueClass
- );
- if ( builderIndexedEntity == null ) {
- continue;
- }
- processContainedInValue(
- collectionValue, queue, valueClass,
- builderIndexedEntity, searchFactoryImplementor
- );
- }
}
else {
- Class<?> valueClass = Hibernate.getClass( value );
- DocumentBuilderIndexedEntity<?> builderIndexedEntity =
searchFactoryImplementor.getDocumentBuilderIndexedEntity(
- valueClass
- );
- if ( builderIndexedEntity == null ) {
- continue;
- }
- processContainedInValue( value, queue, valueClass, builderIndexedEntity,
searchFactoryImplementor );
+ processSingleContainedInInstance( queue, searchFactoryImplementor, value );
}
}
- //an embedded cannot have a useful @ContainedIn (no shared reference)
- //do not walk through them
}
- private void processContainedInValue(Object value, List<LuceneWork> queue,
Class<?> valueClass,
- DocumentBuilderIndexedEntity builderIndexedEntity, SearchFactoryImplementor
searchFactoryImplementor) {
+ /**
+ * A {@code XMember } instance treats a map as a collection as well in which case the
map values are returned as
+ * collection.
+ *
+ * @param member The member instance
+ * @param value The value
+ *
+ * @return The {@code value} casted to collection or in case of {@code value} being a
map the map values as collection.
+ */
+ private <T> Collection<T> getActualCollection(XMember member, Object value)
{
+ Collection<T> collection;
+ if ( Map.class.equals( member.getCollectionClass() ) ) {
+ //hum
+ @SuppressWarnings("unchecked")
+ Collection<T> tmpCollection = ( ( Map<?, T> ) value ).values();
+ collection = tmpCollection;
+ }
+ else {
+ @SuppressWarnings("unchecked")
+ Collection<T> tmpCollection = ( Collection<T> ) value;
+ collection = tmpCollection;
+ }
+ return collection;
+ }
+
+ private <T> void processSingleContainedInInstance(List<LuceneWork> queue,
SearchFactoryImplementor searchFactoryImplementor, T value) {
+ @SuppressWarnings("unchecked")
+ Class<T> valueClass = Hibernate.getClass( value );
+ DocumentBuilderIndexedEntity<T> builderIndexedEntity =
+ searchFactoryImplementor.getDocumentBuilderIndexedEntity( valueClass );
+
+ // it could be we have a nested @IndexedEmbedded chain in which case we have to find
the top level @Indexed entities
+ if ( builderIndexedEntity == null ) {
+ DocumentBuilderContainedEntity<T> builderContainedEntity =
+ searchFactoryImplementor.getDocumentBuilderContainedEntity( valueClass );
+ if ( builderContainedEntity != null ) {
+ processContainedIn( value, queue, builderContainedEntity.metadata,
searchFactoryImplementor );
+ }
+ }
+ else {
+ addWorkForEmbeddedValue( value, queue, valueClass, builderIndexedEntity,
searchFactoryImplementor );
+ }
+ }
+
+ /**
+ * Create a {@code LuceneWork} instance of the entity which needs updating due to the
embedded instance change.
+ *
+ * @param value The value to index
+ * @param queue The current (Lucene) work queue
+ * @param valueClass The class of the value
+ * @param builderIndexedEntity the document builder for the entity which needs updating
due to a update event of the embedded instance
+ * @param searchFactoryImplementor the search factory.
+ */
+ private <T> void addWorkForEmbeddedValue(T value, List<LuceneWork> queue,
Class<T> valueClass,
+ DocumentBuilderIndexedEntity<T> builderIndexedEntity,
SearchFactoryImplementor searchFactoryImplementor) {
Serializable id = ( Serializable ) ReflectionHelper.getMemberValue( value,
builderIndexedEntity.idGetter );
builderIndexedEntity.addWorkToQueue( valueClass, value, id, WorkType.UPDATE, queue,
searchFactoryImplementor );
}
Added:
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Address.java
===================================================================
---
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Address.java
(rev 0)
+++
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Address.java 2009-09-27
12:49:54 UTC (rev 17550)
@@ -0,0 +1,87 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.search.test.embedded.nested;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.hibernate.search.annotations.ContainedIn;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class Address {
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Field(index = Index.TOKENIZED)
+ private String street;
+
+ @Field(index = Index.TOKENIZED)
+ private String city;
+
+ @ContainedIn
+ @OneToMany(mappedBy = "address")
+ private Set<Place> places;
+
+ public Address(String street, String city) {
+ this();
+ this.street = street;
+ this.city = city;
+ }
+
+ private Address() {
+ places = new HashSet<Place>();
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getStreet() {
+ return street;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public Set<Place> getPlaces() {
+ return places;
+ }
+
+ public void addPlace(Place place) {
+ places.add( place );
+ }
+
+ public void setStreet(String street) {
+ this.street = street;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+}
Property changes on:
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Address.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Attribute.java
===================================================================
---
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Attribute.java
(rev 0)
+++
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Attribute.java 2009-09-27
12:49:54 UTC (rev 17550)
@@ -0,0 +1,79 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.search.test.embedded.nested;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+
+import org.hibernate.search.annotations.ContainedIn;
+import org.hibernate.search.annotations.IndexedEmbedded;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class Attribute {
+
+ @Id
+ @GeneratedValue
+ private long id;
+
+ @ManyToOne
+ @ContainedIn
+ private Product product;
+
+ @OneToMany(mappedBy = "attribute", fetch = FetchType.LAZY, cascade = {
CascadeType.PERSIST, CascadeType.REMOVE })
+ @IndexedEmbedded
+ private List<AttributeValue> values;
+
+ private Attribute() {
+ values = new ArrayList<AttributeValue>();
+ }
+
+ public Attribute(Product product) {
+ this.product = product;
+ values = new ArrayList<AttributeValue>();
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public Product getProduct() {
+ return product;
+ }
+
+ public void setProduct(Product product) {
+ this.product = product;
+ }
+
+ public List<AttributeValue> getValues() {
+ return values;
+ }
+
+ public void setValue(AttributeValue value) {
+ values.add( value );
+ }
+}
Property changes on:
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Attribute.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/AttributeValue.java
===================================================================
---
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/AttributeValue.java
(rev 0)
+++
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/AttributeValue.java 2009-09-27
12:49:54 UTC (rev 17550)
@@ -0,0 +1,77 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.search.test.embedded.nested;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+import org.hibernate.search.annotations.ContainedIn;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Store;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class AttributeValue {
+
+ @Id
+ @GeneratedValue
+ private long id;
+
+ @ManyToOne(targetEntity = Attribute.class, fetch = FetchType.EAGER)
+ @ContainedIn
+ private Attribute attribute;
+
+ @Column(name = "_value")
+ @Field(index = Index.TOKENIZED, store = Store.YES)
+ private String value;
+
+ private AttributeValue() {
+ }
+
+ public AttributeValue(Attribute attribute, String value) {
+ this.attribute = attribute;
+ this.value = value;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public Attribute getAttribute() {
+ return attribute;
+ }
+
+ public void setAttribute(Attribute attribute) {
+ this.attribute = attribute;
+ }
+}
\ No newline at end of file
Property changes on:
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/AttributeValue.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/NestedEmbeddedTest.java
===================================================================
---
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/NestedEmbeddedTest.java
(rev 0)
+++
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/NestedEmbeddedTest.java 2009-09-27
12:49:54 UTC (rev 17550)
@@ -0,0 +1,138 @@
+//$Id$
+package org.hibernate.search.test.embedded.nested;
+
+import java.util.List;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.test.SearchTestCase;
+
+
+/**
+ * @author Emmanuel Bernard
+ * @author Hardy Ferentschik
+ */
+public class NestedEmbeddedTest extends SearchTestCase {
+
+ /**
+ * HSEARCH-391
+ *
+ * @throws Exception in case the tests fails
+ */
+ public void testNestedEmbeddedIndexing() throws Exception {
+ Product product = new Product();
+ Attribute attribute = new Attribute( product );
+ product.setAttribute( attribute );
+ AttributeValue value = new AttributeValue( attribute, "foo" );
+ attribute.setValue( value );
+
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ s.persist( product );
+ tx.commit();
+
+ FullTextSession session = Search.getFullTextSession( s );
+ QueryParser parser = new QueryParser( "attributes.values.value", new
StandardAnalyzer() );
+ Query query;
+ List<?> result;
+
+
+ query = parser.parse( "foo" );
+ result = session.createFullTextQuery( query ).list();
+ assertEquals( "unable to find property in attribute value", 1, result.size()
);
+
+
+ s.clear();
+ tx = s.beginTransaction();
+
+ product = ( Product ) s.get( Product.class, product.getId() );
+ product.getAttributes().get( 0 ).getValues().get( 0 ).setValue( "bar" );
+ tx.commit();
+
+ s.clear();
+
+ session = Search.getFullTextSession( s );
+
+ query = parser.parse( "foo" );
+ result = session.createFullTextQuery( query, Product.class ).list();
+ assertEquals( "change in embedded not reflected in root index", 0,
result.size() );
+
+ query = parser.parse( "bar" );
+ result = session.createFullTextQuery( query, Product.class ).list();
+ assertEquals( "change in embedded not reflected in root index", 1,
result.size() );
+
+ s.close();
+ }
+
+
+ /**
+ * HSEARCH-391
+ *
+ * @throws Exception in case the tests fails
+ */
+ public void testNestedEmbeddedIndexingWithContainedInOnCollection() throws Exception {
+ Person john = new Person( "John Doe" );
+ Place eiffelTower = new Place( "Eiffel Tower" );
+ Address addressEiffel = new Address( "Avenue Gustave Eiffel",
"London" );
+ addressEiffel.addPlace( eiffelTower );
+ eiffelTower.setAddress( addressEiffel );
+ john.addPlaceVisited( eiffelTower );
+ eiffelTower.visitedBy( john );
+
+
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ s.persist( john );
+ tx.commit();
+
+ FullTextSession session = Search.getFullTextSession( s );
+ QueryParser parser = new QueryParser( "placesVisited.address.city", new
StandardAnalyzer() );
+ Query query;
+ List<?> result;
+
+
+ query = parser.parse( "London" );
+ result = session.createFullTextQuery( query ).list();
+ assertEquals( "unable to find nested indexed value", 1, result.size() );
+
+
+ s.clear();
+ tx = s.beginTransaction();
+
+ john = ( Person ) s.get( Person.class, john.getId() );
+ john.getPlacesVisited().get( 0 ).getAddress().setCity( "Paris" );
+ tx.commit();
+
+ s.clear();
+
+ john = ( Person ) s.get( Person.class, john.getId() );
+
+ session = Search.getFullTextSession( s );
+
+ query = parser.parse( "London" );
+ result = session.createFullTextQuery( query, Person.class ).list();
+ assertEquals( "change in embedded not reflected in root index", 0,
result.size() );
+
+ query = parser.parse( "Paris" );
+ result = session.createFullTextQuery( query, Person.class ).list();
+ assertEquals( "change in embedded not reflected in root index", 1,
result.size() );
+
+ s.close();
+ }
+
+ protected void configure(org.hibernate.cfg.Configuration cfg) {
+ super.configure( cfg );
+ }
+
+ protected Class<?>[] getMappings() {
+ return new Class[] {
+ Product.class, Attribute.class, AttributeValue.class, Person.class, Place.class,
Address.class
+ };
+ }
+}
\ No newline at end of file
Property changes on:
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/NestedEmbeddedTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Person.java
===================================================================
---
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Person.java
(rev 0)
+++
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Person.java 2009-09-27
12:49:54 UTC (rev 17550)
@@ -0,0 +1,71 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.search.test.embedded.nested;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+@Indexed
+public class Person {
+ @Id
+ @GeneratedValue
+ private long id;
+
+ String name;
+
+ @IndexedEmbedded
+ @ManyToMany(cascade = { CascadeType.ALL })
+ private List<Place> placesVisited;
+
+ private Person() {
+ placesVisited = new ArrayList<Place>( 0 );
+ }
+
+ public Person(String name) {
+ this();
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public List<Place> getPlacesVisited() {
+ return placesVisited;
+ }
+
+ public void addPlaceVisited(Place place) {
+ placesVisited.add( place );
+ }
+
+ public long getId() {
+ return id;
+ }
+}
Property changes on:
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Person.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Place.java
===================================================================
---
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Place.java
(rev 0)
+++
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Place.java 2009-09-27
12:49:54 UTC (rev 17550)
@@ -0,0 +1,87 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.search.test.embedded.nested;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+import javax.persistence.OneToOne;
+
+import org.hibernate.search.annotations.ContainedIn;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.IndexedEmbedded;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class Place {
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Field(index = Index.TOKENIZED)
+ private String name;
+
+ @OneToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
+ @IndexedEmbedded
+ private Address address;
+
+ @ContainedIn
+ @ManyToMany(cascade = { CascadeType.ALL }, mappedBy = "placesVisited")
+ private Set<Person> visitedBy;
+
+ private Place() {
+ this.visitedBy = new HashSet<Person>();
+ }
+
+ public Place(String name) {
+ this();
+ this.name = name;
+ }
+
+ public Address getAddress() {
+ return address;
+ }
+
+ public String getName() {
+
+ return name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setAddress(Address address) {
+ this.address = address;
+ }
+
+ public void visitedBy(Person person) {
+ visitedBy.add( person );
+ }
+
+ public Set<Person> getVisitedBy() {
+ return visitedBy;
+ }
+}
Property changes on:
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Place.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Product.java
===================================================================
---
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Product.java
(rev 0)
+++
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Product.java 2009-09-27
12:49:54 UTC (rev 17550)
@@ -0,0 +1,61 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.search.test.embedded.nested;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+@Indexed
+public class Product {
+ @Id
+ @GeneratedValue
+ private long id;
+
+ @OneToMany(mappedBy = "product", fetch = FetchType.LAZY, cascade = {
CascadeType.PERSIST, CascadeType.REMOVE })
+ @IndexedEmbedded
+ private List<Attribute> attributes;
+
+ public Product() {
+ attributes = new ArrayList<Attribute>();
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public List<Attribute> getAttributes() {
+ return attributes;
+ }
+
+ public void setAttribute(Attribute attribute) {
+ attributes.add( attribute );
+ }
+}
Property changes on:
search/branches/Branch_3_1/src/test/java/org/hibernate/search/test/embedded/nested/Product.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF