Lombok的@Builder与继承和JPA的结合

huangapple go评论79阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年10月20日 21:23:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/64446116.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定