private void storeData(String title, int value, Integer nullableAge) { SomeEntity entry = new SomeEntity(); entry.title = title; entry.age = value; entry.nullableAge = nullableAge; Work work = new Work(entry, entry.title, WorkType.ADD, false); TransactionContextForTest tc = new TransactionContextForTest(); sfHolder.getSearchFactory().getWorker().performWork(work, tc); tc.end(); }
@Test public void testProvidedIdMapping() throws Exception { FullTextSession fullTextSession = Search.getFullTextSession(openSession()); SearchIntegrator sf = fullTextSession.getSearchFactory().unwrap(SearchIntegrator.class); ProvidedIdEntry person1 = new ProvidedIdEntry(); person1.setName("Big Goat"); person1.setBlurb("Eats grass"); ProvidedIdEntry person2 = new ProvidedIdEntry(); person2.setName("Mini Goat"); person2.setBlurb("Eats cheese"); ProvidedIdEntry person3 = new ProvidedIdEntry(); person3.setName("Regular goat"); person3.setBlurb("Is anorexic"); TransactionContextForTest tc = new TransactionContextForTest(); Work work = new Work(person1, 1, WorkType.INDEX); sf.getWorker().performWork(work, tc); work = new Work(person2, 2, WorkType.INDEX); sf.getWorker().performWork(work, tc); Work work2 = new Work(person3, 3, WorkType.INDEX); sf.getWorker().performWork(work2, tc); tc.end(); Transaction transaction = fullTextSession.beginTransaction(); QueryParser parser = new QueryParser("providedidentry.name", TestConstants.standardAnalyzer); Query luceneQuery = parser.parse("Goat"); // we cannot use FTQuery because @ProvidedId does not provide the getter id and Hibernate // Hsearch Query extension // needs it. So we use plain HSQuery HSQuery query = getExtendedSearchIntegrator().createHSQuery(luceneQuery, ProvidedIdEntry.class); assertEquals(3, query.queryResultSize()); transaction.commit(); getSession().close(); }