Skip to content

Custom implementation of CrudRepository.save() not called if generics not declared exactly (reopener) [DATACMNS-1225] #1664

Open
@spring-projects-issues

Description

@spring-projects-issues

Sebastian J opened DATACMNS-1225 and commented

This is a reopener to DATACMNS-1008 (unsure if the old one should be reopened or a new ticket should be created).

The issue is still the same and can be reproduced with these classes:

public interface FooRepository extends CrudRepository<Foo, Long>, FooRepositoryCustom {
	// Workaround as per DATACMNS-1008 still works
	//<X extends Foo> X save(X foo);
}

public interface FooRepositoryCustom {
	Foo doNonstandardThing(Foo foo);
}

public class FooRepositoryImpl implements FooRepositoryCustom {
	
    public Foo save(Foo foo) {
        // Do things
    	return foo;
    }
}

@Service
public class FooService {
    private final FooRepository fooRepo;
    
    @Autowired
    public FooService(FooRepository fooRepo) {
        this.fooRepo = fooRepo;
    }

    public void processFoo(Foo foo) {
    	fooRepo.doNonstandardThing(foo);
        fooRepo.save(foo);
    }
}

As previously, the save method in the custom implementation is never called.

From debugging it looks to me that the error occurs here: org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments.invoke(Method, Object[]) as ReflectionUtils.findMethod in org.springframework.data.repository.core.support.RepositoryFragment.hasMethod(Method) will never find the custom method.
It is looking for a method save(Object) method (due to the generic erasure) but the custom method's parameter is of type Foo


Affects: 2.0.1 (Kay SR1), 2.0.2 (Kay SR2)

Reference URL: https://github.com/derjust/spring-data-dynamodb/tree/issue_77/src/test/java/org/socialsignin/spring/data/dynamodb/issue77

Issue Links:

  • DATACMNS-1008 Custom implementation of CrudRepository.save(…) not called if generics not declared exactly

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions