EN VI

Java - "extends ParentClass" won not inherit ParentClass attributes with @MappedSuperClass?

2024-03-11 07:00:05
How to Java - "extends ParentClass" won not inherit ParentClass attributes with @MappedSuperClass
@MappedSuperclass
public abstract class Auction {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    @Column(nullable = false)
    private String title;
    @Column
    private String description;
    @Column
    private String category;
    @Column(nullable = false)
    private long sellerId;
    @Column
    private String urlPicture;

}

@Getter
@Setter
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "inverseauction")

public class InverseAuction extends Auction{

    @Column(nullable = false)
    private int startingPrice;

    @Column(nullable = false)
    @JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy'T'HH:mm:ss[.SSS][.SS][.S]")
    private LocalDateTime expiryDate;
}

The only attributes my @GetMapping returns are startingPrice and expiryDate , for some reason the Auction attributes are invisible to Auction.

My only guess is to add some SpringBoot Annotation but I don't know which one, I tried some but won't work

Solution:

You need to add getters/setters to your MappedSuperClass and may have to create a custom AllArgsConstructor as Lombok doesn't do a super() in its generated AllArgsConstructor.

Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login