コード例 #1
0
  /**
   * This test will fail because JPA does an update before inserting the new records. The update
   * will set the foreign key to null, which violates the not null constraint.
   */
  @Test
  public void test_replace_collection_with_unidirectional_relation() {
    em.getTransaction().begin();
    Person p = em.find(Person.class, 201L);

    final ArrayList<Car> cars = new ArrayList<Car>();
    p.addCar(new Car("Ferrari"));

    p.setCars(cars);

    em.flush();
    em.getTransaction().commit();
  }
コード例 #2
0
 private void setupTest() {
   Person p = new Person("Sjaak");
   p.addCar(new Car("Opel"));
   em.persist(p);
 }
コード例 #3
0
 private void setupUnidirectional() {
   Person remko = new Person("Remko");
   remko.addCar(new Car("Maserati"));
   em.persist(remko);
 }