-->
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: Updating Lucene indexes when @ContainedIn is not possible
PostPosted: Fri Apr 10, 2009 6:21 pm 
Newbie

Joined: Thu Sep 11, 2008 5:22 pm
Posts: 3
Hello,

I am working on a project that uses Hibernate Search to manage Lucene indexes. One goal of my application to promote modularity, so that pieces of code can be tested independently of the rest of the application. My application has two modules: the student module and the school module. The school module has a build-time dependency on the student module, but the student module can be deployed independently of the student module. Here are my Entities:

Code:
package com.ben.student;
@Entity
public class Student {
  private Integer id;
  private String name;

  @Id
  public Integer getId() { return id; }
  public void setId( Integer id ) { this.id = id; }

  public String getName() { return name; }
  public void setName( String name ) { this.name = name; }

}


Code:
package com.ben.school;

import com.ben.student.Student;
@Entity
public class School {
  private Integer id;
  private String schoolName;
  private List<Student> students;

  @Id
  public Integer getId() { return id; }
  public void setId( Integer id ) { this.id = id; }

  public String getSchoolName() { return schoolName; }
  public void setSchoolName( String schoolName) { this.schoolName = schoolName; }

  @IndexedEmbedded
  @OneToMany
  public List<Student> getStudents() {
    return students;
  }

  public void setStudents( List<Student> students ) {
    this.students = students;
  }
 
}


If I create a school called "School 12" with two students named "Bob" and "Joe", I see two entries in Student's "name" index, and two entries in School's "student.name" index, as expected: Bob and Joe. However, if I change Bob's name to Robert, only the Student's "name" index is updated (not the School's "student.name" index). This is expected behavior, from what I understand, and every article I have read tells me to put a @ContainedIn annotation in my Student class, like so:

Code:
Student.java:
   ....
  @ContainedIn
  @ManyToOne
  private School school;
  public School getSchool() { return school; }
  public void setSchool( School school ) { this.school = school; }


However, as I mentioned earlier, I can't put a @ContainedIn annotation in my Student class, because it is built independently from the School module. Is there another way to tell Hibernate Search to update the School indexes when a student is changed?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 11, 2009 12:55 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
Is there another way to tell Hibernate Search to update the School indexes when a student is changed?

No there is no way.
How could he know what a School is if you remove the entity definition?
IMHO you are going a bit too far with modularization, if you want this behaviour you should at least provide the complete domain model to both applications, then if you like deploy views and business logic indipendently: the entities are the abstraction of you database, when you say
Quote:
if I change Bob's name to Robert, only the Student's "name" index is updated (not the School's "student.name" index)

I understand that the database is still having all tables, and so should your model be complete.

If you were deploying the student application on a reduced database schema (missing the school related tables), then you must remove the entities (as you wanted to do) but then you wouldn't experience this problem, as it wouldn't be possible to change information in a non-existent table.

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


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 11, 2009 12:58 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
actually Emmanuel is currently working on a programmatic-API to configure Search. It might solve your problem by "adding" the contained-in when you need it. It's going to be released in 3.2, you might want to checkout the trunk to get a preview.

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


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.