This rule raises an issue when an interface is designated as a mapper type but does not contain any methods designated as data access object factory methods.

In Java, this specifically refers to interfaces annotated with @Mapper that lack methods annotated with @DaoFactory.

Why is this an issue?

In object-relational mapping frameworks that use code generation, a mapper interface serves as a factory for constructing Data Access Object (DAO) instances. This is a core design pattern of such libraries.

The mapper’s sole purpose is to provide factory method declarations that create and return DAO beans. These factory methods enable dependency injection of DAOs throughout your application. Without any factory method declarations, the mapper interface:

The framework’s code generation mechanism generates implementation code based on the factory method declarations present in the mapper interface. An empty mapper results in generated code that does nothing useful.

In the DataStax Object Mapper framework, the mapper interface uses the @Mapper annotation, and factory methods are declared using the @DaoFactory annotation. According to the Quarkus documentation: "If you intend to construct and inject a specific DAO bean in your own code, then you first must add a @DaoFactory method for it in a @Mapper interface."

What is the potential impact?

An interface marked for code generation without the expected factory methods creates unnecessary code that serves no purpose. This can:

How to fix it

Add at least one @DaoFactory method to the mapper interface. The method should return a DAO interface that is annotated with @Dao.

Code examples

Noncompliant code example

@Mapper
public interface FruitMapper {
    // No @DaoFactory methods // Noncompliant
}

Compliant solution

@Mapper
public interface FruitMapper {
    @DaoFactory
    FruitDao fruitDao();
}

Resources

Documentation