Skip to content

Cannot extend MongoRepository due to private properties / methods / classes #4654

@SledgeHammer01

Description

@SledgeHammer01

Hi,

We implemented some custom functionality by extending JpaRepository, JpaRepositoryFactory, JpaRepositoryFactoryBean and SimpleJpaRepository. It was pretty straight forward once we figured out how to use those 4 classes.

Now we are looking at doing the same for SimpleMongoRepository. However, some crucial properties, methods and classes are package private making it impossible to extend those 4 Mongo variety classes without the use of reflection.

The core problem is really extending MongoRepositoryFactory. For the most basic functionality, we need access to:

  1. MongoOperations -- easy
  2. private <T, ID> MongoEntityInformation<T, ID> getEntityInformation(Class domainClass,
    @nullable RepositoryMetadata metadata) -- requires reflection to call
  3. SimpleMongoRepository::setRepositoryMethodMetadata(CrudMethodMetadata crudMethodMetadata) -- requires reflection to call
  4. no way to access crudMethodMetadata field without reflection
  5. CrudMethodMetadataPostProcessor also have to use reflection, generic Object here
  6. IndexEnsuringQueryCreationListener class is private, had to c&p it into our code

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions