英文:
Lombok @Builder with Inheritance and JPA
问题
我有这个类:
@Entity
@Table(name = "PERSONNE")
@Inheritance(strategy = InheritanceType.JOINED)
@NoArgsConstructor
@AllArgsConstructor
@Data
@SuperBuilder
@ToString
@EqualsAndHashCode(of = { "personneId" })
public class Personne implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "PERSONNE_ID")
protected Long personneId;
}
还有另一个类:
@Entity
@Table(name = "DISSIDENT")
@PrimaryKeyJoinColumn(name = "PERSONNE_ID")
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class Dissident extends Personne {
private static final long serialVersionUID = 1L;
}
但是当我运行测试时,出现了这个错误:
java: constructor Dissident() is already defined in class com.bar.peris.model.Dissident
英文:
I have this class:
@Entity
@Table(name = "PERSONNE")
@Inheritance(strategy = InheritanceType.JOINED)
@NoArgsConstructor
@AllArgsConstructor
@Data
@SuperBuilder
@ToString
@EqualsAndHashCode(of = { "personneId" })
public class Personne implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "PERSONNE_ID")
protected Long personneId;
}
and this other one
@Entity
@Table(name = "DISSIDENT")
@PrimaryKeyJoinColumn(name = "PERSONNE_ID")
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class Dissident extends Personne {
private static final long serialVersionUID = 1L;
}
but when I run a test I got this error:
java: constructor Dissident() is already defined in class com.bar.peris.model.Dissident
答案1
得分: 0
尝试更改 @NoArgsConstructor 和 @AllArgsConstructor 的顺序。类默认情况下具有无参构造函数,除非定义了构造函数。
英文:
Try changing the order of @NoArgsConstructor
@AllArgsConstructor. Class by default have a no arg constructor unless a constructor is defined.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论