Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I choose the name of my jpa repository?

I have to name my interface that extends the CrudRepository with a spacific name (I use spring and Jpa) i.e.

public interface UserRepository extends CrudRepository<User, Long> {}

so in this case I have a Entity with name UserRepository

I tried annotation

@Entity(name="UserCustomRepository")
public interface UserRepository extends CrudRepository<User, Long> {}

but it doesn't work...

like image 443
Shinigami Avatar asked Dec 30 '25 22:12

Shinigami


1 Answers

Apparently it's not possible according to the documentation, see 1.3.3.1. XML Configuration:

Each of these beans will be registered under a bean name that is derived from the interface name, so an interface of UserRepository would be registered under userRepository.

Why do you need a custom name? Besides your example with @Entity(name="UserCustomRepository") is completely broken, @Entity is used to mark JPA entities, not Spring beans/repositories.

like image 68
Tomasz Nurkiewicz Avatar answered Jan 01 '26 15:01

Tomasz Nurkiewicz



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!