I have a two objects with simple @OneToMany relationship which looks as follows:
parent:
@Entity
public class ParentAccount {
@Id
@GeneratedValu
As user1819111 told, @Data
from Lombok is not compatible with @Entity
and FetchType=LAZY
. I had used Lombok.Data
(@Data
) and I was getting this error.
As I don't want do create all get/set, I just put the Lombok @Setter
and @Getter
in your class and all will work fine.
@Setter
@Getter
@Entity
@Table(name = "file")
@SequenceGenerator(name = "File_Sequence", allocationSize=1, sequenceName = "file_id_seq")
public class MyClass{
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "File_Sequence")
@Column(name = "id")
private Long id;
@Column(name = "name")
private String name;
@OneToMany(mappedBy = "file", cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
private Set details = new HashSet<>();
}