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