-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to search an @ElementCollection
PostPosted: Fri Aug 09, 2013 9:26 am 
Newbie

Joined: Sat Feb 26, 2005 11:45 am
Posts: 13
Location: Stockholm, Sweden
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?

_________________
kmike


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.