Пример #1
0
  @Test
  public void test_replace_collection_with_bidirectional_relation() {
    em.getTransaction().begin();
    Department d = em.find(Department.class, 1L);

    final ArrayList<Employee> employees = new ArrayList<Employee>();
    d.addEmployee(new Employee("Sjaak de Vries", d));
    d.addEmployee(new Employee("Henk de Mol", d));

    d.setEmployees(employees);

    em.flush();
    em.getTransaction().commit();
  }
Пример #2
0
 private void setupBidirectional() {
   Department department = new Department("Java");
   department.addEmployee(new Employee("Jakab Gipsz", department));
   department.addEmployee(new Employee("Captain Nemo", department));
   em.persist(department);
 }