gpt4 book ai didi

java - 映射处理器中的内部错误 : java. lang.StackOverflowError

转载 作者:行者123 更新时间:2023-11-29 04:37:13 24 4
gpt4 key购买 nike

在尝试映射我的域对象时,我收到以下 StackOverflowError 异常。我试图忽略导致循环依赖的属性无济于事。

我的领域模型的中心是 WorkoutSet,它有一个 User 和一个 Exercise。

如果我从 WorkoutSetMapper 中删除映射注释,则会按预期生成 UserMapperImpl 和 ExerciseMapperImpl。

Error:(15, 1) java: Internal error in the mapping processor: java.lang.StackOverflowError at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:786) at com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:4652) at com.sun.tools.javac.code.Types.supertype(Types.java:2315) at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1966) at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1955) at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:786) at com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4571) at com.sun.tools.javac.code.Types.asSuper(Types.java:1952) at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1968) at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1955) at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:786) at com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4571) at com.sun.tools.javac.code.Types.asSuper(Types.java:1952) at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1975) at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1955) at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:786) at com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4571) at com.sun.tools.javac.code.Types.asSuper(Types.java:1952) at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1975) at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1955) at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:786) at com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4571) at com.sun.tools.javac.code.Types.asSuper(Types.java:1952) at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1975) at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1955) at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:786) at com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4571) at com.sun.tools.javac.code.Types.asSuper(Types.java:1952) at com.sun.tools.javac.code.Types$4.visitClassType(Types.java:921) at com.sun.tools.javac.code.Types$4.visitClassType(Types.java:844) at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:786) at com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4571) at com.sun.tools.javac.code.Types.isSubtype(Types.java:840) at com.sun.tools.javac.code.Types.isSubtype(Types.java:804) at com.sun.tools.javac.model.JavacTypes.isSubtype(JavacTypes.java:98) at org.mapstruct.ap.internal.util.workarounds.SpecificCompilerWorkarounds.isSubtype(SpecificCompilerWorkarounds.java:76) at org.mapstruct.ap.internal.util.workarounds.TypesDecorator.isSubtype(TypesDecorator.java:68) at org.mapstruct.ap.internal.model.common.Type.isSubType(Type.java:638) at org.mapstruct.ap.internal.model.common.Type.isCollection(Type.java:628) at org.mapstruct.ap.internal.model.common.Type.isCollectionOrMap(Type.java:624) at org.mapstruct.ap.internal.model.common.Type.getAlternativeTargetAccessors(Type.java:598) at org.mapstruct.ap.internal.model.common.Type.getPropertyWriteAccessors(Type.java:419) at org.mapstruct.ap.internal.model.source.TargetReference$BuilderFromTargetMapping.getTargetEntries(TargetReference.java:144) at org.mapstruct.ap.internal.model.source.TargetReference$BuilderFromTargetMapping.build(TargetReference.java:120) at org.mapstruct.ap.internal.model.source.Mapping.init(Mapping.java:227) at org.mapstruct.ap.internal.model.source.SourceMethod$Builder.build(SourceMethod.java:207) at org.mapstruct.ap.internal.processor.MethodRetrievalProcessor.getMethodRequiringImplementation(MethodRetrievalProcessor.java:257) at org.mapstruct.ap.internal.processor.MethodRetrievalProcessor.getMethod(MethodRetrievalProcessor.java:193) at org.mapstruct.ap.internal.processor.MethodRetrievalProcessor.retrieveMethods(MethodRetrievalProcessor.java:148) at org.mapstruct.ap.internal.processor.MethodRetrievalProcessor.retrieveMethods(MethodRetrievalProcessor.java:163) at org.mapstruct.ap.internal.processor.MethodRetrievalProcessor.retrieveMethods(MethodRetrievalProcessor.java:163) at org.mapstruct.ap.internal.processor.MethodRetrievalProcessor.retrieveMethods(MethodRetrievalProcessor.java:163) at org.mapstruct.ap.internal.processor.MethodRetrievalProcessor.retrieveMethods(MethodRetrievalProcessor.java:163) at org.mapstruct.ap.internal.processor.MethodRetrievalProcessor.retrieveMethods ...

我的领域类如下

            @Entity
public class User implements FirstClassDomainObject {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String name;
private String email;
...

@Entity
public class Exercise implements FirstClassDomainObject {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String name;
private String description;
...

@Entity
public class WorkoutSet implements FirstClassDomainObject {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private int repetition;
private double wight;
private LocalDateTime timestamp;
@ManyToOne
private Exercise exercise;
@ManyToOne
private User user;
...

我的DTO类如下

            public class UserResource implements ResourceObject {
private Long id;
private String name;
private String email;
...

public class ExerciseResource implements ResourceObject {
private String name;
private String description;
...

public class WorkoutSetResource implements ResourceObject {
private int repetition;
private double wight;
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime timestamp;
private ExerciseResource exercise;
private UserResource user;
...

我的mapper接口(interface)如下

            @Mapper(componentModel = "spring")
interface UserMapper extends ClassMapper<User, UserResource> {
@Override
default List<Class<?>> getSupportedClasses() {
return Lists.newArrayList(User.class, UserResource.class);
}
}


@Mapper(componentModel = "spring")
interface ExerciseMapper extends ClassMapper<Exercise, ExerciseResource> {
@Override
default List<Class<?>> getSupportedClasses() {
return Lists.newArrayList(Exercise.class, ExerciseResource.class);
}
}

@Mapper(componentModel = "spring", uses = {UserMapper.class, WorkoutSetMapper.class})
interface WorkoutSetMapper extends ClassMapper<WorkoutSet, WorkoutSetResource> {
@Override
default List<Class<?>> getSupportedClasses() {
return Lists.newArrayList(WorkoutSet.class, WorkoutSetResource.class);
}
}

ClassMapper定义如下

            public interface ClassMapper<D extends DomainObject, R extends ResourceObject> {
R map(D domainObject);
D map(R resourceObject);
List<Class<?>> getSupportedClasses();
}

我省略了 getter 和 setter 方法以避免文本墙,但整个代码库可以在这里找到 https://github.com/tonsV2/Lift-Log-Backend .关于我做错了什么的任何线索?

最佳答案

我发现错误了!我已将 WorkoutSetMapper 设置为使用自身。

@Mapper(componentModel = "spring", uses = {UserMapper.class, WorkoutsetMapper.class})
interface WorkoutSetMapper extends ClassMapper<WorkoutSet, WorkoutSetResource> {

虽然我应该有

@Mapper(componentModel = "spring", uses = {UserMapper.class, ExerciseMapper.class})
interface WorkoutSetMapper extends ClassMapper<WorkoutSet, WorkoutSetResource> {

关于java - 映射处理器中的内部错误 : java. lang.StackOverflowError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40821394/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com