Answer the question
In order to leave comments, you need to log in
Add counter to one-to-many?
Hello everyone! Now I have such a one-to-many link
@Entity
@Table(name = "user_table")
@Data
@NoArgsConstructor
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_sequence")
@SequenceGenerator(name = "user_sequence", allocationSize = 1)
@Column(name = "user_id")
private Long id;
private String firstName;
private String lastName;
private String middleName;
// @Email(message = "Email is not correct")
private String email;
@Enumerated(EnumType.STRING)
private Gender gender;
@OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true)
private List<Item> itemList = new ArrayList<>();
}
@Entity
@Table(name = "item_table")
@Data
@NoArgsConstructor
public class Item implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "item_sequence")
@SequenceGenerator(name = "item_sequence", allocationSize = 1)
@Column(name = "item_id")
private Long id;
@Enumerated(EnumType.STRING)
private Category category;
private String name;
private double price;
private LocalDate localDate;
}
Answer the question
In order to leave comments, you need to log in
The opinion of a java champion and author of a book on persistence on this topic.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question