For the domain object mapping to relational databases, hibernate and other persistence frameworks do a lot of work, so that the business logic only needs to interact with the persistence layer such as hibernate, without the need to interact directly with the specific database.
This gives programmers a lot of convenience in business logic processing, as long as the domain object can be.
When using Lucene for indexing and search development, the most frequently encountered concept is document and field, and one of the things you have to do in a program is to map the properties of a domain object to the field of document, and when searching, You also build DTOs (Data Transfor object) based on the document and field to return to the Web layer. This is similar to one of the drawbacks of EJB, which cannot be returned to the Web layer as an entity bean, but as a dto that encapsulates the entity bean.
What we want is the convenience of a technology like Pojo, which is persisted in domain object, and is also domain object returned to the Web layer.
When we index and search domain object, we also want to be able to operate directly on the domain object level, rather than dealing directly with document and field. And we can do that with the compass framework.
Compass uses the Lucene search engine framework, which provides a set of Open-source, high-performance, flexible search frameworks that provide search capabilities for users ' applications. It can also be integrated with existing frameworks such as spring and hibernate.
COMAPSS's API structure is very similar to hibernate, and if a hibernate programmer uses Comapass, the API is basically handy.
Let's take a look at an example
compassconfiguration config = new compassconfiguration (). Configure ();
Compass Compass = Config.buildcomapss ();
Compasssession session = Compass.opensession ();
Compasstransaction tx = NULL;
Try
{
tx = Session.begintransaction ();
Book book = new book ();
Book.setname ("C + + programming Idea");
Book.setauthor ("Bruce Eckel");
Session.save (book);
Tx.commit ();
} catch (Exception e)
{
if (tx!=null)
{
tx.rollback ();
}
}finally
{
session.close ();
}
Hiberanete programmer should be very familiar with the above code, compass completely let you away from the Lucene API, so that your code more focused on business logic, and the index and search for the matter to the Compass bar. This also brings an advantage, that is, the use of compass is very easy to the existing system to add search capabilities.
So how to let domain object is compass use, of course, and hibernate like, as long as the completion of some Domai object configuration file can be, specific can read compass with example.