Hello,
I cannot get hibernate search to work with @ElementCollection.
I have a ClassA
Code:
@Entity
@Table
@Indexed
public class classA {
@Id
private Long myId;
@IndexedEmbedded
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE, optional = false)
@JoinColumn(name = "CLASSB_ID", referencedColumnName = "CLASSB_ID", nullable = false)
private ClassB classB;
//... getter and setters.
}
My ClassB with an @ElementCollection.
Code:
@Entity
@Table
@Indexed
public class ClassB {
@Id
private Long myId;
@IndexedEmbedded
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "CLASSB_SSYK_KOD", joinColumns = @JoinColumn(name = "CLASSB_ID"))
@FieldBridge(impl=CollectionToCSVBridge.class)
@Column(name = "SSYK_KOD")
private Set<String> ssykKodLista = new HashSet<String>();
//... getter and setters.
}
My CollectionToCSVBridge class
Code:
public class CollectionToCSVBridge implements StringBridge {
public String objectToString(Object value) {
if(value != null) {
StringBuffer buf = new StringBuffer();
Collection<?> col = (Collection<?>)value;
Iterator<?> it = col.iterator();
while(it.hasNext()) {
String next = it.next().toString();
buf.append(next);
if(it.hasNext())
buf.append(", ");
}
return buf.toString();
}
return null;
}
}
In my search I have this expression
Code:
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(this.getEntityManager());
QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(ClassA.class).get();
BooleanJunction<BooleanJunction> bool = queryBuilder.bool();
bool.must(queryBuilder
.keyword()
.onField("classb.ssykKodLista")
.matching("1234")
.createQuery());
// executing query...
After I have started my server I don't have any classb.ssykKodLista looking in the index with Luke.
Also running the query will result in an exception:
org.hibernate.search.SearchException: Unable to find field classb.ssykKodLista in com.mypackage.ClassA
If I replace the @IndexedEmbedded in ClassB with @Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
I can see classB.ssykKodLista in Luke. An execution of the query will produce the error:
org.hibernate.search.bridge.BridgeException: Exception while calling bridge#objectToString
class: com.mypackate.ClassA
path: classb.ssykKodLista
Annotate with @Field does not seem right but after struggeling with this for a long time Im getting more confused...
Anyone have an opinion?