-->
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: Problem manually updating index for IndexedEmbedded changes
PostPosted: Fri Sep 16, 2011 6:48 am 
Newbie

Joined: Fri Sep 17, 2010 8:23 am
Posts: 5
I need to manually update the index but run into some trouble when updating @IndexedEmbedded objects.

In my domain I have Relations which can have multiple Addresses. The OneToMany relation from Relation to Address is annotated with @IndexedEmbedded and the ManyToOne from Address to Relation annotated with @ContainedIn.

Once an Address is updated (postal code changes to 'YY1234') I update the index by:

Code:
Transaction tx = fullTextSession.beginTransaction();
Object address = fullTextSession.load(Address.class, 8);
fullTextSession.index(address);
tx.commit();


However I'm not able to find the updated relation when searching for 'YY1234' (I'm searching for the Relation, not the Address)

This all does work when I update the complete corresponding Relation instead of only the Address.

My questions:
    - Am I doing something wrong?
    - If not, isn't HSearch supposed to figure this out itself (because of the @ContainedIn annotation).
    - Will HSearch 4 handle this in an easier way?

I found that writing some code to figure out which 'parent' object should be updated to avoid the problem isn't a trivial task and in many cases just plain impossible. You can't just go 'up' following all @ContainedIn marked relationships recursively and hope that this will bring you to the (possible multiple) parent domain classes. In many (more complex) domain models you will find yourself walking in never ending rounds.


Top
 Profile  
 
 Post subject: Re: Problem manually updating index for IndexedEmbedded changes
PostPosted: Fri Sep 16, 2011 8:14 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

could you provide you annotated classes? Who is the owner of the relationship? Are you sure that the relationship gets properly updated when you just change the address? Normally you have to edit both ends of a bidirectional relationship.

--Hardy


Top
 Profile  
 
 Post subject: Re: Problem manually updating index for IndexedEmbedded changes
PostPosted: Fri Sep 16, 2011 3:09 pm 
Newbie

Joined: Fri Sep 17, 2010 8:23 am
Posts: 5
My classes look like (simplified)

Code:
@Indexed
@Entity
public class Relation implements Serializable { // I should have called this Person instead of Relation to avoid confusion with the word relationship
   @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   private int relationsID;

   @Field(index=Index.YES, store=Store.NO)
   private String name;

   @IndexedEmbedded
   @OneToMany(mappedBy="relation")
   private Set<Address> addresses;
}

@Indexed
@Entity
public class Address implements Serializable {
   @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   private int addressesID;

   @Field(index=Index.YES, store=Store.NO)
   private String address;

   @Field(index=Index.YES, store=Store.NO)
   private String postalCode;

   @ContainedIn
   @ManyToOne
   @JoinColumn(name="RelationsID", nullable=false)
   private Relation relation;
}


So if I'm correct I should call Address the owner of the relationship.

I'm not updating the relationship but just the postal code in the Address. The update isn't performed through hibernate but with a manual query (which is something I can't change).

I get a notification of this update by a database trigger which results in a manual update like:
Code:
fullTextSession.index(address);


The problem is that when I try to search for a Relation (Person) by the new updated postal code ('YY1234') I don't get any results. Relevant code:
Code:
...
String[] onFields = new String[]{"name", "addresses.postalCode"};
FullTextQuery persistenceQuery =  fullTextEntityManager.createFullTextQuery(qb.keyword().onFields(onFields).matching("YY1234").createQuery(), Relation.class);
List result = persistenceQuery.getResultList();
...


Things work properly if I update the complete relation object like the code below. But I would like to avoid this step. Figuring out which object to load to update the index can be very hard in a more complex domain model.
Code:
Object relation = fullTextSession.load(Relation.class, 10);
fullTextSession.index(relation);


Top
 Profile  
 
 Post subject: Re: Problem manually updating index for IndexedEmbedded changes
PostPosted: Thu Sep 22, 2011 2:46 pm 
Newbie

Joined: Fri Sep 17, 2010 8:23 am
Posts: 5
Would be great if a member of the hibernate team can shed some light on this.

Edit: 21 okt 2011
For anyone interested in this thread: I reported this as a bug/feature request HSEARCH-939 on Jira.
I'm still not sure if it is a bug or just me trying to do something in the wrong way.


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.