DateBridge for LocalDate in Hibernate Search

I’m using Hibernate search 11.5.2.Final in a SpringBoot app.

I’m trying to search for the field createdAt of the entity Book.

when I run it, the application exits with an exception like

Unable to create bean for LocalDateBridge

I get the same kind of Exception for fields of type Long also

my entity looks like this

@Indexed
@Entity
public class Book {
    @Id 
    private Long id;


    @Field
    @DateBridge(resolution=Resolution.DAY)
    private LocalDate createdAt;

    // Other fields and setters & getters
}

Here is the Full stack trace


2019-08-05 13:42:57.789  WARN 14452 --- [nio-8080-exec-1] g.e.SimpleDataFetcherExceptionHandler    : Exception while fetching data (/Books) : Exception while calling bridge#objectToString
    entity class: com.app.model.Book
    entity property path: createdAt
    field bridge: TwoWayString2FieldBridgeAdaptor [stringBridge=org.hibernate.search.bridge.builtin.time.impl.LocalDateBridge@4ef6ee21]

org.hibernate.search.bridge.BridgeException: Exception while calling bridge#objectToString
    entity class: com.app.model.Book
    entity property path: createdAt
    field bridge: TwoWayString2FieldBridgeAdaptor [stringBridge=org.hibernate.search.bridge.builtin.time.impl.LocalDateTimeBridge@4ef6ee21]
    at org.hibernate.search.bridge.util.impl.ContextualExceptionBridgeHelper.buildBridgeException(ContextualExceptionBridgeHelper.java:104) ~[hibernate-search-engine-5.11.2.Final.jar:5.11.2.Final]
    at org.hibernate.search.bridge.util.impl.ContextualExceptionBridgeHelper$TwoWayConversionContextImpl.objectToString(ContextualExceptionBridgeHelper.java:161) ~[hibernate-search-engine-5.11.2.Final.jar:5.11.2.Final]
    at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.objectToString(DocumentBuilderIndexedEntity.java:274) ~[hibernate-search-engine-5.11.2.Final.jar:5.11.2.Final]
    at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.objectToString(DocumentBuilderIndexedEntity.java:1066) ~[hibernate-search-engine-5.11.2.Final.jar:5.11.2.Final]
    at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.objectToString(DocumentBuilderIndexedEntity.java:1049) ~[hibernate-search-engine-5.11.2.Final.jar:5.11.2.Final]
    at org.hibernate.search.query.dsl.impl.FieldContext.objectToString(FieldContext.java:75) ~[hibernate-search-engine-5.11.2.Final.jar:5.11.2.Final]
    at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.buildSearchTerm(ConnectedMultiFieldsTermQueryBuilder.java:149) ~[hibernate-search-engine-5.11.2.Final.jar:5.11.2.Final]
    at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:113) ~[hibernate-search-engine-5.11.2.Final.jar:5.11.2.Final]
    at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:81) ~[hibernate-search-engine-5.11.2.Final.jar:5.11.2.Final]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) [spring-aop-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) [spring-aop-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_40]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_40]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_40]
    at io.leangen.graphql.metadata.execution.SingletonMethodInvoker.execute(SingletonMethodInvoker.java:21) ~[spqr-0.9.9.jar:na]
    at io.leangen.graphql.metadata.Resolver.resolve(Resolver.java:100) ~[spqr-0.9.9.jar:na]
    at io.leangen.graphql.execution.OperationExecutor.lambda$execute$1(OperationExecutor.java:93) ~[spqr-0.9.9.jar:na]
    at io.leangen.graphql.execution.OperationExecutor$$Lambda$1440/231233146.aroundInvoke(Unknown Source) ~[na:na]
    at io.leangen.graphql.execution.OperationExecutor.execute(OperationExecutor.java:98) ~[spqr-0.9.9.jar:na]
    at io.leangen.graphql.execution.OperationExecutor.execute(OperationExecutor.java:94) ~[spqr-0.9.9.jar:na]
    at io.leangen.graphql.execution.OperationExecutor.execute(OperationExecutor.java:59) ~[spqr-0.9.9.jar:na]
    at io.leangen.graphql.generator.OperationMapper$$Lambda$1152/966240044.get(Unknown Source) ~[na:na]
    at graphql.execution.ExecutionStrategy.fetchField(ExecutionStrategy.java:261) [graphql-java-11.0.jar:na]
    at graphql.execution.ExecutionStrategy.resolveFieldWithInfo(ExecutionStrategy.java:202) [graphql-java-11.0.jar:na]
    at graphql.execution.AsyncExecutionStrategy.execute(AsyncExecutionStrategy.java:70) [graphql-java-11.0.jar:na]
    at graphql.execution.Execution.executeOperation(Execution.java:159) [graphql-java-11.0.jar:na]
    at graphql.execution.Execution.execute(Execution.java:101) [graphql-java-11.0.jar:na]
    at graphql.GraphQL.execute(GraphQL.java:573) [graphql-java-11.0.jar:na]
    at graphql.GraphQL.parseValidateAndExecute(GraphQL.java:515) [graphql-java-11.0.jar:na]
    at graphql.GraphQL.executeAsync(GraphQL.java:489) [graphql-java-11.0.jar:na]
    at graphql.GraphQL.execute(GraphQL.java:420) [graphql-java-11.0.jar:na]
    at io.leangen.graphql.spqr.spring.web.servlet.DefaultGraphQLExecutor.execute(DefaultGraphQLExecutor.java:23) [graphql-spqr-spring-boot-autoconfigure-0.0.4.jar:na]
    at io.leangen.graphql.spqr.spring.web.servlet.DefaultGraphQLExecutor.execute(DefaultGraphQLExecutor.java:11) [graphql-spqr-spring-boot-autoconfigure-0.0.4.jar:na]
    at io.leangen.graphql.spqr.spring.web.GraphQLController.executeJsonPost(GraphQLController.java:42) [graphql-spqr-spring-boot-autoconfigure-0.0.4.jar:na]
    at io.leangen.graphql.spqr.spring.web.GraphQLController$$FastClassBySpringCGLIB$$db77e769.invoke(<generated>) [graphql-spqr-spring-boot-autoconfigure-0.0.4.jar:na]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) [spring-core-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) [spring-aop-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at net.bull.javamelody.MonitoringSpringInterceptor.invoke(MonitoringSpringInterceptor.java:76) [javamelody-core-1.77.0.jar:1.77.0]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) [spring-aop-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at io.leangen.graphql.spqr.spring.web.servlet.DefaultGraphQLController$$EnhancerBySpringCGLIB$$3b8cd271.executeJsonPost(<generated>) [graphql-spqr-spring-boot-autoconfigure-0.0.4.jar:na]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.19.jar:9.0.19]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_40]
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.time.temporal.TemporalAccessor
    at org.hibernate.search.bridge.builtin.time.impl.TemporalAccessorStringBridge.objectToString(TemporalAccessorStringBridge.java:42) ~[hibernate-search-engine-5.11.2.Final.jar:5.11.2.Final]
    at org.hibernate.search.bridge.util.impl.TwoWayString2FieldBridgeAdaptor.objectToString(TwoWayString2FieldBridgeAdaptor.java:33) ~[hibernate-search-engine-5.11.2.Final.jar:5.11.2.Final]
    at org.hibernate.search.bridge.util.impl.ContextualExceptionBridgeHelper$TwoWayConversionContextImpl.objectToString(ContextualExceptionBridgeHelper.java:158) ~[hibernate-search-engine-5.11.2.Final.jar:5.11.2.Final]
    ... 151 common frames omitted


2
Leave a Reply

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

Try removing @DateBridge(resolution=Resolution.DAY): it’s not useful in your case since the resolution of a local date is already the day.

The problem was probably caused by explicit resolution not being supported for java.time types, but only for legacy java.util.Date/java.util.Calendar types (where it may actually be useful).

If this doesn’t solve the problem, please paste the complete stack trace in your question.

Jason
Guest

According to your stack trace, you are passing a String object to the query builder, whereas a LocalDate object is expected, since your field is of type LocalDate.
Parse the user-provided string to a LocalDate, then pass that object to the query builder.