public class HibernateSearchAtopOgmTest extends JpaTestCase {
@Test
public void testHibernateSearchJPAAPIUsage() throws Exception {
getTransactionManager().begin();
final FullTextEntityManager ftem = Search.getFullTextEntityManager( getFactory().createEntityManager() );
final Insurance insurance = new Insurance();
insurance.setName( "Macif" );
ftem.persist( insurance );
getTransactionManager().commit();
ftem.clear();
getTransactionManager().begin();
final QueryBuilder b = ftem.getSearchFactory()
.buildQueryBuilder()
.forEntity( Insurance.class )
.get();
final Query lq = b.keyword().onField( "name" ).matching( "Macif" ).createQuery();
final FullTextQuery ftQuery = ftem.createFullTextQuery( lq, Insurance.class );
ftQuery.initializeObjectsWith( ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID );
final List<Insurance> resultList = ftQuery.getResultList();
assertThat( getFactory().getPersistenceUnitUtil().isLoaded( resultList.get( 0 ) ) ).isTrue();
assertThat( resultList ).hasSize( 1 );
for ( Object e : resultList ) {
ftem.remove( e );
}
getTransactionManager().commit();
ftem.close();
}