@Entity
@Audited
public static class Alert {
@ManyToMany
private List<RuleName> ruleNames = new ArrayList<>();
}
@Entity
@Audited
public static class RuleName {
}
@Test
@Priority(7)
public void testClearAddDetachedOutsideTransaction() {
EntityManager em = getEntityManager();
em.getTransaction().begin();
List<RuleName> clone = Arrays.asList(em.find(RuleName.class, ruleName1Id), em.find(RuleName.class, ruleName2Id));
em.getTransaction().rollback();
em.getTransaction().begin();
Alert alert = em.find(Alert.class, alertId);
alert.getRuleNames().clear();
alert.getRuleNames().addAll(clone);
em.persist(alert);
em.getTransaction().commit();
}