@Test public void testFullTextFilterDefAtMappingLevel() throws Exception { FullTextSession s = Search.getFullTextSession(openSession()); Transaction tx = s.beginTransaction(); Address address = new Address(); address.setStreet1("Peachtree Rd NE"); address.setStreet2("Peachtnot Rd NE"); address.setOwner("test"); Calendar c = GregorianCalendar.getInstance( TimeZone.getTimeZone("GMT"), Locale.ROOT); // for the sake of tests c.set(2009, Calendar.NOVEMBER, 15); address.setLastUpdated(c); s.persist(address); address = new Address(); address.setStreet1("Peachtnot Rd NE"); address.setStreet2("Peachtree Rd NE"); address.setLastUpdated(c); address.setOwner("testowner"); s.persist(address); tx.commit(); s.clear(); tx = s.beginTransaction(); QueryParser parser = new QueryParser("id", TestConstants.standardAnalyzer); org.apache.lucene.search.Query luceneQuery = parser.parse("street1:Peachtnot"); FullTextQuery query = s.createFullTextQuery(luceneQuery).setProjection(FullTextQuery.THIS, FullTextQuery.SCORE); query.enableFullTextFilter("security").setParameter("ownerName", "testowner"); assertEquals("expecting 1 results", 1, query.getResultSize()); @SuppressWarnings("unchecked") List<Object[]> results = query.list(); for (Object[] result : results) { s.delete(result[0]); } tx.commit(); s.close(); }
/** * Removes the address. * * @param address the address */ public void removeAddress(Address address) { this.addresses.remove(address); address.setOwner(null); }
/** * Adds the address. * * @param address the address */ public void addAddress(Address address) { address.setOwner(this); this.addresses.add(address); }