JPA, как избежать обновления ассоциированной сущности в @manytoone или @onetooneJAVA

Программисты JAVA общаются здесь
Anonymous
JPA, как избежать обновления ассоциированной сущности в @manytoone или @onetoone

Сообщение Anonymous »

У меня есть две сущности, подобные этим: < /p>

Код: Выделить всё

@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);
hibernate будет обновлять уведомление . Но в этом бизнес -обоснование я не хочу менять уведомление при обновлении уведомлений. Но я не знаю, почему это грязно ??

Подробнее здесь: https://stackoverflow.com/questions/448 ... r-onetoone

Вернуться в «JAVA»