-->
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.  [ 4 posts ] 
Author Message
 Post subject: Search Listerner in a mix of annoation and .hbm.xml files
PostPosted: Mon Feb 22, 2010 4:47 pm 
Beginner
Beginner

Joined: Fri Jun 29, 2007 2:19 pm
Posts: 26
Location: Fremont, CA
Most of our entities use Annotations but for a couple, we had to move to .hbm.xml as we needed to use "dynamic-component" which AFAIK is not available in annotations. In such a case, Hibernate search captures the CRUD events for annotated entities but not for the other entities. I can add event listeners, but that for the entire sessionFactory. Would it cause hibernate search to fire CRUD events twice in case of annotated entities?

What is the recommended approach for hibernate search in case of hybrid domain object Model.

_________________
-shailesh


Top
 Profile  
 
 Post subject: Re: Search Listerner in a mix of annoation and .hbm.xml files
PostPosted: Tue Feb 23, 2010 4:25 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
In my previous project we used hbm files and Hibernate Search annotations so it's ok and it will work. The other alternative is using the Programmatic API from Hibernate Search. This means you do not use annotations on your entities but build a SearchMapping which constructs the entities and fields you want indexing/searching. Here is a link http://relation.to/Bloggers/Emmanuel


Hope that helps.


Top
 Profile  
 
 Post subject: Re: Search Listerner in a mix of annoation and .hbm.xml files
PostPosted: Tue Feb 23, 2010 4:54 am 
Beginner
Beginner

Joined: Fri Jun 29, 2007 2:19 pm
Posts: 26
Location: Fremont, CA
Let me clarify the scenario a bit

Code:
@Entity @Indexed
@Table(name = "B")
public class B implements java.io.Serializable {
        ...
     @ManyToOne(cascade = { CascadeType.PERSIST ,CascadeType.MERGE,CascadeType.REFRESH }, fetch = FetchType.EAGER)
   @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
   @JoinColumn(name = "a_id", nullable = true)
   @IndexedEmbedded
   private A a;
}

//Defined in a.hbm.xml
@indexed
public class A implements java.io.Serializable {
     ...
    //Cardinality(oneToMany) defined in a.hbm.xml with inverse="true"
    @ContainedIn
    private Set<B> bs = new HashSet<B>(0);
}


Any change in A, update the indexes of A, but no impact to indexes of B. Insert/Delete are not an issue as they only happen via Object B.
If I remove the @index on A, no hibernateSearch event gets fired. I also tried adding post-update listener to the session.
SearchMapping looks interesting, when is 3.2 GA is expected?

_________________
-shailesh


Top
 Profile  
 
 Post subject: Re: Search Listerner in a mix of annoation and .hbm.xml files
PostPosted: Tue Feb 23, 2010 5:38 pm 
Beginner
Beginner

Joined: Fri Jun 29, 2007 2:19 pm
Posts: 26
Location: Fremont, CA
I got it to work by changing fetch from join to select
Object A, Before:
Code:
<set name="bs"  lazy="false" fetch="join" inverse="true">
  <key column="b_id"/>
  <one-to-many class="B"/>
</set>

Object A, After:
Code:
<set name="bs"  lazy="false" fetch="select" inverse="true">
  <key column="b_id"/>
  <one-to-many class="B"/>
</set>

_________________
-shailesh


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.