Charlie Wu
Charlie Wu

Reputation: 7757

Spring roo 1.2 how to add finder to repository layer

I created an entity with fields

entity jpa --class ~.domain.Account
field string --fieldName email
field string --fieldName password

When I created a repository

repository jpa --interface ~.repositories.AccountRepository --entity ~.domain.Account

I want to add a finder to the repository, is there a similar way to add a finder like to add finders in entity?

finder add findAccountsByEmail

Upvotes: 1

Views: 3138

Answers (1)

Pete M
Pete M

Reputation: 36

Finders are only available for active record entities. To generate the query using repositories create a new method in the repository class, decorate it with the @Query annotation and use JPQL to write the query. Your example would be:

@Query("select a from Account as a where a.email = :email")
@Transactional(readOnly = true)
List<Account> findAccountsByEmail(@Param("email") String email)

Upvotes: 2

Related Questions