Skip to content

SimpleR2dbcRepository does not support custom subclasses #416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ada-waffles opened this issue Jul 25, 2020 · 3 comments
Closed

SimpleR2dbcRepository does not support custom subclasses #416

ada-waffles opened this issue Jul 25, 2020 · 3 comments
Labels
type: bug A general bug

Comments

@ada-waffles
Copy link
Contributor

This section of the Spring Data Reference Documentation describes how a custom repository base class can be used.

It notes that, when doing so, one must override/provide a constructor with the signature (EntityInformation<T, ID>, StoreOperations, ...).

In the case of SimpleR2dbcRepository, that would be SimpleR2dbcRepository(RelationalEntityInformation<T, ID>, R2dbcEntityOperations, R2dbcConverter). However, that constructor is package-private.

Attempting to override the public constructor yields an error on bean instantiation saying to provide the other signature. It is also not possible to convert from the desired signature to the public one, as there does not appear to be a publicly-accessible way to pull the ReactiveDataAccessStrategy back out of the R2dbcEntityOperations (The trick the R2dbcEntityTemplate constructor uses to pull it out of the DatabaseClient won't work as DefaultDatabaseClient is also package-private).

Is there a particular reason that constructor is package-private? The fact that it is seems to me to be the only thing preventing the use of a custom base class. Or is there something else I'm missing?

@mp911de mp911de added the type: bug A general bug label Jul 25, 2020
@mp911de mp911de added the status: blocked An issue that's blocked on an external project change label Aug 4, 2020
@mp911de
Copy link
Member

mp911de commented Aug 4, 2020

Waiting for #368.

@mp911de mp911de removed the status: blocked An issue that's blocked on an external project change label Aug 4, 2020
@mp911de mp911de closed this as completed Aug 4, 2020
@dkublik
Copy link

dkublik commented Aug 12, 2020

@duke9509 as a temporary workaround you can always use the second constructor with null value for ReactiveDataAccessStrategy

    public BaseRepositoryImpl(RelationalEntityInformation<T, ID> entity, R2dbcEntityOperations entityOperations,
        R2dbcConverter converter) {
        super(entity, entityOperations.getDatabaseClient(), converter, null);
    }

I've checked - it's working.

SimpleR2dbcRepository ignores it anyway

public SimpleR2dbcRepository(RelationalEntityInformation<T, ID> entity, DatabaseClient databaseClient,
			R2dbcConverter converter, ReactiveDataAccessStrategy accessStrategy) {

		this.entity = entity;
		this.entityOperations = new R2dbcEntityTemplate(databaseClient);
		this.idProperty = Lazy.of(() -> converter //
				.getMappingContext() //
				.getRequiredPersistentEntity(this.entity.getJavaType()) //
				.getRequiredIdProperty());
	}

@ada-waffles
Copy link
Contributor Author

@dkublik You know... I am kind of embarrassed that I didn't think of that, haha. Thank you very much! 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants