-->
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: Double direction @IndexedEmbedded @ContainedIn
PostPosted: Wed Jun 26, 2013 3:54 am 
Newbie

Joined: Sat Feb 26, 2005 11:45 am
Posts: 13
Location: Stockholm, Sweden
Hi,

Is it possible to perform searches from both sides of an hibernate search association?

I have an indexed ClassA with association:
Code:
@IndexedEmbedded
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "ClassB_ID", nullable = false)
private ClassB classB


And an indexed ClassB with a @ContainedIn association:
Code:
@ContainedIn
@OneToMany(mappedBy = "classB", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Set<ClassA> classAlist = new HashSet<ClassA>();


I can with this associations perform searches with ClassA as root object.
However I would also like to perform other search queries with ClassB as root object and be able to perform searches on classAlist, is this possible.

It is not possible to put both @IndexedEmbedded and @ContainedIn on both sides...

--------------
I edit this query with my solution...
To be able to search from a root object associated with ClassB and then towards the classAlist (@containedIn) I changed the annotation to:
Code:
@ContainedIn
@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
@FieldBridge(impl = MyBridge.class)   
@OneToMany(mappedBy = "classB", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Set<ClassA> classAlist = new HashSet<ClassA>();


And MyBride.class looks like this:
Code:
public class MyBridge implements TwoWayFieldBridge {

    @Override
    public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
        @SuppressWarnings("unchecked")
        Set<ClassA> classAlist= (Set<ClassA>) value;

        StringBuilder sb = new StringBuilder();
        for (ClassA classA : classAlist) {
            sb.append(classA.getClassR().getClassM().getClassMId()).append(" ");
        }

        luceneOptions.addFieldToDocument(name, sb.toString(), document);
    }

    @Override
    public Object get(String name, Document document) {
        return document.get(name);
    }

    @Override
    public String objectToString(Object object) {
        return object.toString();
    }
}


Also, in the search query we now only reference to classAlist and not the path (classA.classR.classM.classMId)

_________________
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.