}
@Test
public void testHibernateSearchJPAAPIUsage() throws Exception {
final Session session = openSession();
Transaction transaction = session.beginTransaction();
final FullTextSession fts = Search.getFullTextSession( session );
final Insurance insurance = new Insurance();
insurance.setName( "Macif" );
fts.persist( insurance );
transaction.commit();
fts.clear();
transaction = fts.beginTransaction();
final QueryBuilder b = fts.getSearchFactory()
.buildQueryBuilder()
.forEntity( Insurance.class )
.get();
final Query lq = b.keyword().onField( "name" ).matching( "Macif" ).createQuery();
final FullTextQuery ftQuery = fts.createFullTextQuery( lq, Insurance.class );
ftQuery.initializeObjectsWith( ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID );
final List<Insurance> resultList = ftQuery.list();
assertThat( resultList ).hasSize( 1 );
for ( Object e : resultList ) {
fts.delete( e );
}
transaction.commit();
fts.close();
}