/* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are * distributed under license by Red Hat, Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.search.test.query; import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.search.Query; import org.hibernate.Transaction; import org.hibernate.search.FullTextQuery; import org.hibernate.search.FullTextSession; import org.hibernate.search.Search; import org.hibernate.search.SearchException; import org.hibernate.search.test.SearchTestCase; import org.hibernate.search.test.TestConstants; /** * HSEARCH-162 - trying to index an entity which is not marked with @Indexed * * @author Hardy Ferentschik */ public class QueryUnindexedEntityTest extends SearchTestCase { public void testQueryOnAllEntities() throws Exception { FullTextSession s = Search.getFullTextSession( openSession() ); Transaction tx = s.beginTransaction(); Person person = new Person(); person.setName( "Jon Doe" ); s.save( person ); tx.commit(); tx = s.beginTransaction(); QueryParser parser = new QueryParser( TestConstants.getTargetLuceneVersion(), "name", TestConstants.standardAnalyzer ); Query query = parser.parse( "name:foo" ); FullTextQuery hibQuery = s.createFullTextQuery( query ); try { hibQuery.list(); fail(); } catch ( SearchException e ) { assertTrue( "Wrong message", e.getMessage().startsWith( "There are no mapped entities" ) ); } tx.rollback(); s.close(); } protected Class<?>[] getAnnotatedClasses() { return new Class[] { Person.class, }; } }