在@Entity类之外声明@NamedNativeQuery和@SqlResultSetMapping

时间:2019-04-18 16:05:15

标签: java spring-boot spring-data-jpa

在我的maven项目中,我有2个模块:

com.example.common

com.example.myfeature

common模块中,我有一个包含entities类的程序包名称@Entity

myfeature模块中,我有一个包含vosDTO类的程序包名称Value Object

com.example.common
+-----------------entities
+-------------------------Doctor.java
com.example.myfeature
+-----------------vos
+--------------------DoctorDTO.java
+-----------------repository
+--------------------DoctorRepository.java

我这样声明了@SqlResultSetMapping

@SqlResultSetMapping(
        name = "resultMappingQuery",
        classes = @ConstructorResult(
                targetClass = DoctorDTO.class,
                columns = {
                        @ColumnResult(name = "doctorId", type = Long.class),
                        @ColumnResult(name = "gender", type = Gender.class),
                        @ColumnResult(name = "dateOfBirth", type = Date.class),
                        @ColumnResult(name = "description", type = String.class),
                        @ColumnResult(name = "avatarImg", type = String.class),
                        @ColumnResult(name = "title", type = String.class),
                        @ColumnResult(name = "addressTitle", type = String.class),
                        @ColumnResult(name = "address", type = String.class),
                        @ColumnResult(name = "department", type = String.class),
                })
)

如果我在公共模块中声明了@SqlResultSetMapping,则必须将DoctorDTO的{​​{1}}导入myfeature

问题是我无法将common模块导入到myfeature模块中,所以我会提出紧密耦合问题。

我想在common模块中的某个地方声明@SqlResultSetMapping

我该怎么做?

0 个答案:

没有答案