Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data JPA: Named method without JpaRepository

I would like to have a single-method interface with the method:

boolean existsByStrAndStatus(String str, Character status);

and have it work as-is as a named method. However, all the examples I've seen of this inherit from JpaRepository and I don't want to inherit from this interface as any implementation that I write (for testing purposes) also need to inherit all the built-in convenience methods that JpaRepository provide such as findAll, flush etc.. I am well aware of mocking frameworks, but I am looking for a solution that doesn't involve using for example Mockito.

Is there an alternative to JpaRepository where I can still @Autowire this repository as I see fit, but if I need to write an implementation I only need to implement my own method?

like image 331
kinbiko Avatar asked Jul 10 '26 11:07

kinbiko


1 Answers

I think you should create custom implementation of your interface:

class TestRepository implements Repository

Which will implement only your custom method and rest leave unimplemented. Then you can use it in your tests.

like image 89
ByeBye Avatar answered Jul 13 '26 05:07

ByeBye



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!