Skip to content

RSQLJPASupport.toSpecification(filter) erroneously reports No entity manager bean found in application context #191

@Nephthys76

Description

@Nephthys76

I'm new to using this library, and it looks like it would fit my needs perfectly, but I've spent 3 days trying to get it to work and have been thus far unsuccessful.

As long as I don't send a filter and I manually create my Specification, everything works fine using the findAll(spec, pageable) method. But once I send a filter from my controller endpoint, the translation of the RSQL string into a Specification produces an error.

I have tried many different ways to ensure the RSQLVisitorBase class is getting the proper EntityManager, which is auto-configured with JPA, but nothing has worked. I know my Entity and my EntityManager are good, because I am able to do all CRUD actions on my entity and it's reflected in my database (postgres). This code has been in production for almost 2 years. I am only now trying to implement server-side filtering (and paging).

Here is some background info:

  • I'm using Spring Boot 3, version 3.3.5
  • I'm using rsql-jpa-spring-boot-starter, version 6.0.32
  • During startup, I am printing out all elements in my EntityManager, and I see all expected elements, including the element for which I'm trying to create a Specification from my RSQL string
  • This is the command that is causing the error: var spec: Specification<Analysis> = RSQLJPASupport.toSpecification(filter) (I am coding in Kotlin, which compiles into Java and is compatible with all Java libraries)
  • This is my error (exerpts only):
ERROR i.g.p.r.RSQLVisitorBase:211 [ReqGuid:] - [class com.ilmn.kratos.database.domain.Analysis] not found in EntityManager: []
...
org.springframework.dao.InvalidDataAccessApiUsageException: No entity manager bean found in application context
...
Caused by: java.lang.IllegalStateException: No entity manager bean found in application context
	at io.github.perplexhub.rsql.RSQLVisitorBase.getManagedType(RSQLVisitorBase.java:212)
	at io.github.perplexhub.rsql.RSQLJPAPredicateConverter.findPropertyPathInternal(RSQLJPAPredicateConverter.java:81)

I have tried manually setting my entity manager in RSQLVisitorBase context in several different ways. I have tried manually exposing my entity manager as a Bean. I have also tried manually invoking the auto-configuration of RSQLJPASupport in hopes that it would pick up my correct EntityManager, but I still get the same error.

This method, called from my Application (main) class proves that my entity is IN my spring context:

    @PostConstruct
    fun logEntities() {
        val entities = entityManager.metamodel.entities.map { it.javaType.name }
        println("Entities in EntityManager: $entities")
    }

seen in my log (exerpt):

Entities in EntityManager: [..., com.ilmn.kratos.database.domain.Analysis, ...]

Here is the declaration of my Repository:

@Repository
interface AnalysisCrudRepository: CrudRepository<Analysis, String>, JpaSpecificationExecutor<Analysis> {

Here is my RSQL that I'm trying to convert to a Specification:

name=like=*Adv*

Thanks in advance for any help. This library could potentially save me lots of time, as I need to implement server-side paging and filtering for several entities.

Tonya

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions