-->
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.  [ 3 posts ] 
Author Message
 Post subject: [Hibernate Search] Searching collections
PostPosted: Mon Jun 23, 2008 2:30 am 
Newbie

Joined: Tue Jun 26, 2007 3:08 am
Posts: 10
Hello,
I have problem with querying collections - maybe I will show you my code first:
Code:
@Entity
@Indexed
public class PhotoGallery implements Serializable {
   
   @Id
   @DocumentId
   @GeneratedValue(strategy = GenerationType.AUTO)
   private int id;
   
   @Field(store = Store.NO, index = Index.TOKENIZED)
   private String galleryName;
   
   @OneToMany(fetch = FetchType.LAZY)
   @JoinColumn(name = "gallery_id")
   @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
        org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
   @IndexColumn(name = "list_position")
   @Fetch(value = FetchMode.SELECT)
   private List<GalleryImage> galleryImages = new ArrayList<GalleryImage> ();

... more fields setters / getters
}

@Entity
@Indexed
public class GalleryImage implements Serializable {
   @Id
   @DocumentId
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Integer id;
   
   @ManyToOne
   @JoinColumn (name = "gallery_id", nullable = false, updatable = false, insertable = true)
   @Cascade({CascadeType.SAVE_UPDATE})
   private PhotoGallery owningGallery;
   
   @Field(index = Index.TOKENIZED, store = Store.NO)
   private String imageComment;

... more fields setters / getters
}


First of all probably I can't put @IndexedEmbedded on galleryImages because it's @OneToMany, and in documentation stays: "Any @ManyToMany, @*ToOne and @Embedded attribute can be annotated with @IndexedEmbedded. The attributes of the associated class will then be added to the main entity index. In the previous example, the index will contain the following fields".
In my search I need to ask for PhotoGallery objects which have given query words in field galleryName and also in galleryImages -> imageComment.
The only idea I have for now is to put in PhotoGallery a getter which will return all the imageComment as concatenated String made after iterating all the galleryImages. I think it will be huge performance problem, but maybe there is other idea to use search in way I want?

Thx in advance for any help,
Adr


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 3:51 am 
Hibernate Team
Hibernate Team

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

have you actually tried to place @IndexedEmbedded on your galleryImages property? I think it will work and the documentation is just not correct. Give it a go.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 4:44 am 
Newbie

Joined: Tue Jun 26, 2007 3:08 am
Posts: 10
hardy.ferentschik wrote:
Hi,

have you actually tried to place @IndexedEmbedded on your galleryImages property? I think it will work and the documentation is just not correct. Give it a go.

--Hardy


I have checked it again and it works - thx for answer.
Code:
   @OneToMany(fetch = FetchType.LAZY)
   @JoinColumn(name = "gallery_id")
   @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
        org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
   @IndexColumn(name = "list_position")
   @Fetch(value = FetchMode.SELECT)
   @IndexedEmbedded
   private List<GalleryImage> galleryImages = new ArrayList<GalleryImage> ();


Best regards,
Adr


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