In a Spring Boot project I have a JPA entity, like this:
@Entity
public class Account {
}
and then I have the repository to query the database:
public interface AccountRepository extends JpaRepository<Account, UUID> {
}
In both the app and tests it's easy to get the repository by doing:
@Autowired
private AccountRepository accountRepository;
How can I get hold of the repository in a method in the Account class? I tried @Autowired but it didn't work.
For those arguing about design, my question is not about design. I have written this code in Ruby and Rails as well as Clojure with HugSQL and it was self contained and concise: when creating a new record I also generate a compact unique alphanumeric id. In Ruby on Rails I released it as a library: https://github.com/pupeno/random_unique_id