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.
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-NNNNN") @SuppressWarnings("unchecked")
public void testSingletonNonIdSetBug() {
Session s = openSession();
YourAnnotatedEntity yourEntity1 = new YourAnnotatedEntity( 1L, "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( 1l, (long) result.get( 0 ).getId() );
s.close();
}
}
Where I expect it to fail is in the line
assertEquals( 1l, (long) result.get( 0 ).getId() );
Because in my code, although luke shows the @id values are there, they aren't populated in the returned entity. On queries with multiple results, the @id values are populated. Test Code I can't get this to work with these versions in the supplied pom.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>
I get
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)
...
Any help appreciated. |