![]() If we wanted to create a persistent, on-disk database and indexes, only a few lines in the Hibernate XML configuration file would change. As this is a JUnit test, we’re taking advantage of the in-memory database capability of the H2 Database, as well as the in-memory Lucene index capability.Annotations – both JPA and Hibernate Search annotations – trigger the Hibernate framework to do most of the work for us relative to creating the database table for the entity, persisting the test data in the database and causing Lucene to build and populate its indexes with the data we want to be able to search.There’s no code to write to update the index. Hibernate Search automatically creates the Lucene index and keeps it up-to-date in the background, as persistent entities are created/updated/deleted in the database.However, you may be able to build and run the unit tests without it. ![]() Simply use the Eclipse “import” function. I’ve attached the source code to this post as an Eclipse project. The example is based on Hibernate Search, version 4.3.0.There are a few things I believe are worth noting before we dig in: In this post, we’re going to take a quick look at a sample application (really, it’s a JUnit test case) that uses Hibernate Core, with Java Persistence API (JPA) annotations, to persist a simple entity to a relational database and Hibernate Search to run some searches against the Lucene indexes created/updated as the Hibernate-managed entities are updated in the database. In my previous post " Adding the Power of Search to Your Hibernate App – The Easy Way," I talked a little about when you may want to consider integrating a search capability into your application using Hibernate Search, as well as a bit about Hibernate Search and how it relates to Hibernate Core, Lucene and Solr.
0 Comments
Leave a Reply. |