Rajshree Rai
Rajshree Rai

Reputation: 642

Creating composable repositories in micronaut

I am trying to implement a method using a composable repository in micronaut.

I have:

@Repository
public interface EmployeeRepository extends CrudRepository<Employee, Long>, EmployeeRepositoryCustom {
}

Here, the EmployeeRepositoryCustom is an interface with the method 'list()':

public interface EmployeeRepositoryCustom {
    List<Employee> list();
}

Then I have EmployeeRepositoryCustomImpl class that implements the methods of the interface:

public class EmployeeRepositoryCustomImpl implements EmployeeRepositoryCustom {
    @PersistenceContext
    EntityManager em;

    @Override
    @Transactional
    public List<Employee> list() {

       // implementation code
    }
}

When I call the method using:

@Inject

EmployeeRepository employeeRepository;

public List<Employee> get(){
     return employeeRepository.list();
}

I get the following message:

java.lang.IllegalStateException: Micronaut Data method is missing compilation time query information. Ensure that the Micronaut Data annotation processors are declared in your build and try again with a clean re-build. 


I've tried adding the annotation @Repository on EmployeeRepositoryCustom and EmployeeRepositoryCustomImpl, but it still gives the same error message. Is there any way to get this done?

I know I can just inject the EmployeeRepositoryCustom class and access the method, but I want to do it using the composable repository method. Because, the employee repository comes from another schema (not the default datasource but another datasource) and I would like to be able to specify the schema like:

@Repository("schema2")

Upvotes: 2

Views: 1177

Answers (1)

James Kleeh
James Kleeh

Reputation: 12228

You shouldn't be creating an implementation of the interface. If you want to have methods with your own code, you can create the repository as an abstract class and leave the methods you want implemented for you as abstract and then you can create any concrete methods.

Upvotes: 1

Related Questions