Код: Выделить всё
@Entity
@Table(name = "article")
@EntityListeners({AuditingEntityListener.class})
public class Notification implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
private Integer id;
@OneToMany(mappedBy = "notification", cascade = {CascadeType.PERSIST})
private List langs;
@OneToMany(mappedBy = "notification", cascade = {CascadeType.PERSIST})
private List targets;
@LastModifiedDate
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "updated_at")
private Date updatedAt;
@CreatedDate
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created_at")
private Date createdAt;
}
@Entity
@Table(name = "article_count")
@EntityListeners({AuditingEntityListener.class})
public class NotificationTarget implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@JsonIgnore
private Integer id;
@Column(name = "user_id")
private String userId;
@ManyToOne(optional = false)
@JoinColumn(name = "notification_id")
private Notification notification;
}
< /code>
Уведомление и уведомление.NotificationTarget notificationTarget = notificationTargetRepository.findByNotificationIdAndUserId(
notificationId, userId);
notificationTarget.setUserId(userId);
notificationTargetRepository.save(notificationTarget);
Подробнее здесь: https://stackoverflow.com/questions/448 ... r-onetoone