-->
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.  [ 8 posts ] 
Author Message
 Post subject: [Hibernate Search] problem with index creation
PostPosted: Sun Dec 16, 2007 1:03 pm 
Newbie

Joined: Thu Dec 06, 2007 11:40 pm
Posts: 6
new post

Hi,
I have three entities Document, Author and DocumentAuthors.
Document contains set of DocumentAuthors and DocumentAuthors has just 2 foreign keys - DocumentId and AuthorId.

I am trying to achieve following:

To get list of all documents written by specified author(s), or other way around to get author(s) who wrote specified document(s).
No sure how I should map this so it would work both ways.

Getting query done would actually be step 2...right now I cannot get even index created properly.

Code:
/**
* Document entity.
*
*/
@Entity
@Indexed
@Table(name = "document", catalog = "library", uniqueConstraints = {})
public class Document implements java.io.Serializable {

   // Fields
   @Id
   @Column(name = "documentId", unique = true, nullable = false, insertable = true, updatable = true)
   @DocumentId
   private Long documentId;
       private String documentName;
   ....
   

   @IndexedEmbedded
   @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "document")
      public Set<DocumentAuthors> getDocumentAuthors() {
         return this.documentAuthors;
   }   

        @Field(index=Index.TOKENIZED)
   @Column(name = "DocumentName", unique = false, nullable = true, insertable = true, updatable = true, length = 256)
   public String getDocumentName() {
      return this.documentName;
   }





Code:

/**
* DocumentAuthors entity.
*
*/

@Entity
@Indexed
@Table(name = "documentAuthors", catalog = "library", uniqueConstraints = {})
public class DocumentAuthors implements java.io.Serializable {

   // Fields

   private DocumentAuthorsId id;
   private Document document;
   private Author author;


   // Property accessors
   @EmbeddedId
   @DocumentId
   @AttributeOverrides( {
         @AttributeOverride(name = "documentId", column = @Column(name = "DocumentID", unique = false, nullable = false, insertable = true, updatable = true)),
         @AttributeOverride(name = "authorId", column = @Column(name = "AuthorID", unique = false, nullable = false, insertable = true, updatable = true)) })
   public DocumentAuthorsId getId() {
      return this.id;
   }

   @IndexedEmbedded
   @ManyToOne(cascade = {}, fetch = FetchType.LAZY)
   @JoinColumn(name = "documentId", unique = false, nullable = false, insertable = false, updatable = false)
   public Document getDocument() {
      return this.document;
   }


   @IndexedEmbedded
   @ManyToOne(cascade = {}, fetch = FetchType.LAZY)
   @JoinColumn(name = "Author_ID", unique = false, nullable = false, insertable = false, updatable = false)
   public Author getAuthor() {
      return this.author;
   }
}


Code:

/**
* Author entity.
*
*/
@Entity
@Indexed
@Table(name = "author", catalog = "library", uniqueConstraints = {})
public class Author implements java.io.Serializable {

   // Fields

   private Long authorId;
   private String authorName;

   private Set<DocumentAuthors> documentAuthors = new HashSet<Objectauthor>(0);
   private Set<DocumentAuthors> documentAuthors_1 = new HashSet<Objectauthor>(0);
 
   // Property accessors
   @Id
   @DocumentId
   @Column(name = "Author_ID", unique = true, nullable = false, insertable = true, updatable = true)
   public Long getAuthorId() {
      return this.authorId;
   }

        @Field(index=Index.TOKENIZED)
   @Column(name = "Author_Name", unique = false, nullable = false, insertable = true, updatable = true, length = 128)
   public String getAuthorName() {
      return this.authorName;
   }





   @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "author")
   public Set<DocumentAuthors> getDocumentAuthors() {
      return this.documentAuthors;
   }



   @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "author")
   public Set<DocumentAuthors> getDocumentAuthors_1() {
      return this.documentAuthors_1;
   }



}


Last edited by peter123123 on Sun Dec 16, 2007 8:56 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 16, 2007 7:09 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Before going the Hibernate Search way, what is wrong with a plain old HQL query?

_________________
Emmanuel


Top
 Profile  
 
 Post subject: [Hibernate Search] problem with index creation and mapping
PostPosted: Sun Dec 16, 2007 7:20 pm 
Newbie

Joined: Thu Dec 06, 2007 11:40 pm
Posts: 6
Sorry I meant really to say text query not HQL query. this thing is already running I am just to add text search capabilities I will edit title.

Ok I am just a bit not sure or let me put plainly confused :-) about this.
I have Document - oneToMany link to DocumentcAuthors so I guess I should use @ContainedIn but @ContainedIn is just link to Authors (@ManyToOne) so I am not sure how to make build index from Document through DocumentAuthors to Authors. I've seen your examples and run through this forum but could not find anything like this.


Top
 Profile  
 
 Post subject: Re: [Hibernate Search] problem with index creation and mappi
PostPosted: Sun Dec 16, 2007 8:22 pm 
Newbie

Joined: Thu Dec 06, 2007 11:40 pm
Posts: 6
ok let me start from here I need DocumentAuthor be get indexed - but I am getting error id cannot be indexed.

DocumentAuthorsId is a class containg both Document and Author id's.


Code:
   public class DocumentAuthors implements java.io.Serializable {

   // Fields

   private DocumentAuthorsId id;
   private Document document;
   private Author author;


   // Property accessors
   @EmbeddedId
   @DocumentId
   @AttributeOverrides( {
         @AttributeOverride(name = "documentId", column = @Column(name = "DocumentID", unique = false, nullable = false, insertable = true, updatable = true)),
         @AttributeOverride(name = "authorId", column = @Column(name = "AuthorID", unique = false, nullable = false, insertable = true, updatable = true)) })
   public DocumentAuthorsId getId() {
      return this.id;
   }


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 22, 2007 4:51 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
For composite ids, you need to write a custom TwoWayStringBridge to do the translation between the object world and the index world.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 22, 2007 4:52 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Ah and unfortunately I don't think @indexEmbedded will work out of the box then :( (ie inside the embedded id)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 2:18 pm 
Newbie

Joined: Thu Dec 06, 2007 11:40 pm
Posts: 6
That is most unfortunate - I am just surprised that I am "first" (in this forum at least) to run into this on such a common DB relationship.

Anyways plan B kicked in and just used plain Lucene API instead and surprisingly I just adding about 2 pages of code and I have it done including index update when Hibernate fires updates/deletes.

Thanks for comments anyways.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 08, 2008 6:45 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can you open a JIRA issue with the summary of you need?

_________________
Emmanuel


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