hibernate lucene integration

JPAでの確認をしようとhibernate annotationのリファマニみたらlucene integrationってあって、気になったのでテストクラスを動かして確認。
hibernate-coreとannotationと依存jarにクラスパスを通して、hibernate.propertiesも同様に通せば、振る舞いだけはActivePerlとか、おいおいにするとして、てっとりばやく確認できる。

Session s = getSessions().openSession();
s.getTransaction().begin();
s.persist(
  new Document( "Hibernate in Action", "Object/relational mapping with Hibernate", 
      "blah blah blah" ));
s.getTransaction().commit();
s.close();

IndexReader reader = IndexReader.open( new File( getBaseIndexDir(), "Documents" ) );
int num = reader.numDocs();
assertEquals( 1, num );
TermDocs docs = reader.termDocs( new Term( "Abstract", "Hibernate" ) );
org.apache.lucene.document.Document doc = reader.document( docs.doc() );
assertFalse( docs.next() );
docs = reader.termDocs( new Term( "Title", "Action" ) );
doc = reader.document( docs.doc() );
assertFalse( docs.next() );
assertEquals( "1", doc.getField( "Id" ).stringValue() );
reader.close();

書き込みだけなのね。読み込みはおいおい考察。でも、結構おもしろいかも。Documentのクラスはこちら。

@Entity
@Indexed(index = "Documents")  
public class Document {
	private Long id;
	private String title;
	private String summary;
	private String text;

	Document() {
	}

	public Document(String title, String summary, String text) {
		super();
		this.summary = summary;
		this.text = text;
		this.title = title;
	}

	@Id
	@GeneratedValue
	@Keyword(id = true)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Text
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Unstored(name = "Abstract")
	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	@Lob
	@Unstored
	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

太字がLucene用アノテ。昔のHibernateにはマッピングファイル上で、Persisterのインターフェースの宣言ができて永続化の実装を拡張できたんだけどなぁ、最近は、どうなったんだろう。。。おいおい確認。