Hibernate Search 5.7.0.Beta2 when returning a single entry does not populate the field annotated with @id.
This is the test code, however I can't get it to run. I see this error in my application. {code:java} package org.hibernate.search.bugs;
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.apache.lucene.search.Query; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.search.FullTextSession; import org.hibernate.search.Search; import org.hibernate.search.query.dsl.QueryBuilder; import org.hibernate.search.test.SearchTestBase; import org.hibernate.search.testsupport.TestForIssue; import org.junit.Test;
public class YourTestCase extends SearchTestBase {
@Override public Class<?>[] getAnnotatedClasses() { return new Class<?>[]{ YourAnnotatedEntity.class }; }
@Test @TestForIssue(jiraKey = "HSEARCH-2541") // Please fill in the JIRA key of your issue @SuppressWarnings("unchecked") public void testSingletonNonIdSetBug() {
Session s = openSession();
YourAnnotatedEntity yourEntity1 = new YourAnnotatedEntity( 0L, "example" ); YourAnnotatedEntity yourEntity2 = new YourAnnotatedEntity( 1L, "alpha" );
Transaction tx = s.beginTransaction(); s.persist( yourEntity1 ); s.persist( yourEntity2 ); tx.commit();
FullTextSession session = Search.getFullTextSession( s ); QueryBuilder qb = session.getSearchFactory().buildQueryBuilder().forEntity( YourAnnotatedEntity.class ).get(); Query query = qb.keyword().onField( "name" ).matching( "example" ).createQuery();
List<YourAnnotatedEntity> result = (List<YourAnnotatedEntity>) session.createFullTextQuery( query ).list(); assertEquals( 1, result.size() ); assertEquals( 0L, (long) result.get( 0 ).getId() );
s.close(); } } {code} Where I expect it to fail is in the line {code:java} assertEquals( 1l 0L , (long) result.get( 0 ).getId() ); {code} Because in my code, although _luke_ shows the {{@id}} values are there, they aren't populated in the returned entity, they are null.
On queries with multiple results, the {{@id}} values are populated.
h2. Test Code I can't get this to work with these versions in the supplied pom.xml {code:xml} <properties> <version.org.hibernate.search>5.7.0.Beta2</version.org.hibernate.search> <version.org.hibernate>5.2.6.Final</version.org.hibernate> <version.com.h2database>1.4.193</version.com.h2database> <version.junit>4.12</version.junit> <version.org.slf4j>1.7.22</version.org.slf4j> </properties> {code} I get {code} java.lang.NoClassDefFoundError: org/hibernate/tool/schema/internal/exec/JdbcConnectionContext at org.hibernate.search.test.DefaultTestResourceManager.buildSessionFactory(DefaultTestResourceManager.java:81) at org.hibernate.search.test.DefaultTestResourceManager.openSessionFactory(DefaultTestResourceManager.java:73) at org.hibernate.search.test.SearchTestBase.setUp(SearchTestBase.java:45) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ... {code}
Any help appreciated. |
|