-->
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.  [ 6 posts ] 
Author Message
 Post subject: Help on Indexing Updates
PostPosted: Tue Dec 15, 2009 3:41 am 
Newbie

Joined: Tue Dec 15, 2009 3:33 am
Posts: 13
Location: Melbourne, Australia
Hello,

New to Hibernate Search. Hopefully this is a quick fix.

Have 2 main objects that I want to index. Media and Tag.

Media Object contains the following annotations against Tag list:

@IndexedEmbedded
@XStreamAlias("tags")
@OneToMany
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@JoinColumn(name = "media_id")
@ContainedIn
private List<Tag> tags;

Tag Obejct contains the following annotations against Media list:

@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE })
@XStreamOmitField // XStream
@IndexedEmbedded(depth = 2) // Search (Wasn't on here before)
@ContainedIn
private Media media;

I need to have both these objects indexed so I can query the index to get either Media out or Tag object out. My problem is that when I update Media object, the list of Tags associated with it is also updated (given new Id's). When I check the Tag object index with Luke tool, the Tag object has the new Tag ID but does not the existing Media ID.

I suspect it has something to do with how I have the @ContainedIn and @IndexedEmbedded annoations but its slowly doing my head in and if anyone can give me a quick bit of help, that would be great.


Top
 Profile  
 
 Post subject: Re: Help on Indexing Updates
PostPosted: Tue Dec 15, 2009 9:42 am 
Hibernate Team
Hibernate Team

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

I don't quite understand your problem. Why do the tag ids change on a Media update? Maybe you could post some more context information. How does your session code looks like and what is the exact problem you see.

Besides of that I don't think that you need the @ContainedIn annotation on tags.

--Hardy


Top
 Profile  
 
 Post subject: Re: Help on Indexing Updates
PostPosted: Thu Dec 17, 2009 6:11 am 
Newbie

Joined: Tue Dec 15, 2009 3:33 am
Posts: 13
Location: Melbourne, Australia
Hello,

Thanks for the reply.

This is part of a web service call. When updates occur to the Media object, if any of the Tag values change, then all the Tags (including already persisted ones) are sent into the web service. This is done for performance issues so that duplicate Tags are not stored in the database for a Media object. It also means that for duplicates to not occur, we don't have to sort through what could be many Tags and check that there's no duplicates or to check for which Tag(s) may have been deleted.

Due to this occuring, when the Media object is saved, there are new Tag objects with no ID's. These new tag objects are saved and new ID's are associated with them in a Tag table with a reference to Media_ID.

This is fine but when inspecting the Lucene Tag object index, there is no update to the Media ID. There is a new entry for the new Tag with correct ID but not the associated Media ID.

I am currently indexing both Tag and Media objects in different indexes.

Below is some more code of the Tag and Media objects:

Media Object
Code:
@Entity @Table(name = "media")    // Hibernate
@XStreamAlias("media")         // XStream
@Indexed                  // Hibernate Search
@Analyzer(impl = StandardAnalyzer.class)
public class Media implements Serializable, Tagable{
   @Id
   @GeneratedValue
   @DocumentId
   private Long id;

   @IndexedEmbedded(depth = 1)   // Hibernate Search (Require 1 depth level to get the Tag properties)
   @XStreamAlias("tags")
    @OneToMany
    @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
    @JoinColumn(name = "media_id")
   private List<Tag> tags;

}


Tag Object

Code:
@Entity
@Table(name="tag")
@XStreamAlias("tag")
@Indexed
@Analyzer(impl = StandardAnalyzer.class)
public class Tag implements Serializable {

   @XStreamOmitField
   @Id
   @GeneratedValue
   @DocumentId(name = "tag_id")
   private Long id;

   @Field(index=Index.UN_TOKENIZED, store=Store.YES, name="value_untokenized")
   private String value;

   @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE })
   @XStreamOmitField   // XStream
   @IndexedEmbedded(depth = 3)   // Hibernate Search (Require 3 depth levels to get the media.MediaSyndicatedPartner.ClientId)
   private Media media;
}


All updates to Media occur in a Hibernate transaction. As you can see above, there are JPA annotations, not sure if this may impact things.

JARS:
Hibernate 3.4GA Annotations
Hibernate Search 3.1.1GA
Hibernate EntityManager 3.4GA
Hibernate 3

Lucene Core 2.9.1
Lucene Misc 2.9.1
Lucene Analysers 2.9.1
Lucene Queries 2.9.1

Any more help with this would be great. I think I may just be missing a key point between Hibernate and Hibernate Search but can't seem to figure it out.

Thanks


Top
 Profile  
 
 Post subject: Re: Help on Indexing Updates
PostPosted: Tue Dec 29, 2009 2:41 am 
Newbie

Joined: Tue Dec 15, 2009 3:33 am
Posts: 13
Location: Melbourne, Australia
Wondering if anyone is able to help out with the above issue I'm having?
Still have no joy in figuring this out.

Thanks.


Top
 Profile  
 
 Post subject: Re: Help on Indexing Updates
PostPosted: Tue Dec 29, 2009 8:21 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hello,
1) Lucene 2.9 is quite dangerous, it's still not working fine on trunk. Basic functionality works, but some stuff (Compression, filters) don't, with Search 3.1 you should use Lucene 2.4.x
2) It looks like the media-tags relation you're mapping should be bi-directional, but the "mappedBy" clause is missing int the annotations; I guess that when you save the Tag it's "media" property is null, so you don't get any media id indexed. I'd suggest adding Validator annotations to add some constraints on your model.
Also check that you set both parts of the relation on the objects.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Help on Indexing Updates
PostPosted: Mon Jan 04, 2010 5:42 pm 
Newbie

Joined: Tue Dec 15, 2009 3:33 am
Posts: 13
Location: Melbourne, Australia
Hello,

I have sorted the issue out. Thanks very much for the replies. I have swapped back in the lucene 2.4 jars. Also examining the code outside of lucene when updating Media objects, as s.grinovero suggested, I found the even though the Tag objects were being updated in the database when Media objects were being saved, I needed to have the Media object reference in the Tag objects for Lucene to also update its documents.

Again, thanks a lot for the help and now our Lucene index code is working great.


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