-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to search in related entity (Hibernate search)
PostPosted: Fri Oct 12, 2012 1:22 am 
Newbie

Joined: Wed Oct 10, 2012 12:54 am
Posts: 2
I am getting no where trying this thing .My requirement is to search records by their name

Following are my related classes:

RecordFolderAnalysis.java

Code:
@Indexed
public class RecordFolderAnalysis extends AuditableEntity implements Serializable {

    @ManyToOne
    @JoinColumn(name = "arrivalId", nullable = false)
    @ContainedIn
    private RecordFolderArrival recordFolderArrival;

}



RecordFolderArrival.java


Code:
@Indexed
public class RecordFolderArrival extends BaseEntity implements Serializable
  {

    @Column(name="recordName", unique = true, nullable = false)
    @Field(index = Index.UN_TOKENIZED)
    private String recordName;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "recordFolderArrival", fetch = FetchType.LAZY, targetEntity = RecordFolderAnalysis.class)
    @IndexedEmbedded
    private List<RecordFolderAnalysis> recordFolderAnalysis=new ArrayList<>();

  }


Follwing is my DAO class method:


Code:
@Override
    public List<T> search(final String queryString, final String... fields) {
        List searchResult = hibernateTemplate.executeFind(new HibernateCallback<Object>() {
            org.hibernate.Query fullTextQuery1 = null;

            @Override
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                try {
                    System.out.println("in do in hibernate");
                    FullTextSession fullTextSession = Search.getFullTextSession(session);
                    Transaction tx = fullTextSession.beginTransaction();
                    QueryBuilder builder=fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(persistentClass).get();
                    Query luceneQuery=builder.keyword().onField("recordFolderArrival.recordName").matching(queryString).createQuery();
                    fullTextQuery1 = fullTextSession.createFullTextQuery(luceneQuery);


                    for (Object o : fullTextQuery1.list()) {
                        System.out.println("Values" + o);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return fullTextQuery1.list();

            }
        });

        return searchResult;
    }


So I am searching by Record-Name by setting field name as recordFolderArrival.recordName. But It is throwing an exception saying

Quote:
recordFolderArrival.recordName field does'nt exist in RecordFolderAnalysis.


I am very new to Hibernate Search so if anyone can help me working this thing out. Thanks and Don't worry about @Entity and other annotation they are placed where they have to be its just I have not included them in snippet.


Top
 Profile  
 
 Post subject: Re: How to search in related entity (Hibernate search)
PostPosted: Tue Jan 15, 2013 10:41 am 
Newbie

Joined: Tue Jan 15, 2013 9:56 am
Posts: 7
Have you used Luke to explore the Lucene index? Perhaps things are not being indexed exactly as you expect.


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

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.