[jira] [Created] (OPENJPA-2874) Embeddable objects are not updated and orphaned references removed

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (OPENJPA-2874) Embeddable objects are not updated and orphaned references removed

Mark Struberg (Jira)
Will Dazey created OPENJPA-2874:
-----------------------------------

             Summary: Embeddable objects are not updated and orphaned references removed
                 Key: OPENJPA-2874
                 URL: https://issues.apache.org/jira/browse/OPENJPA-2874
             Project: OpenJPA
          Issue Type: Bug
          Components: jpa
    Affects Versions: 2.2.2
            Reporter: Will Dazey


Very similar to https://github.com/hibernate/hibernate-orm/pull/3817. Tested on 2.2.2 and I could not find an existing bug that fixed this already.

Entities:
```
@Entity
public class RaceDriver {
        @Id private Integer id;
        @Embedded private Car car;
        private String name;
}

@Embeddable
public class Car {
        @Id private Integer id;
        @OneToOne(orphanRemoval = true, fetch = FetchType.LAZY)
        private Engine engine;
        @Column private String color;
}

@Entity
public class Engine {
        @Id private Integer id;
        private Integer horsePower;
}
```

Test:
```
    em.getTransaction().begin();

    final Engine engine = new Engine( 1, 275 );
    final Car car = new Car(1, engine, "red");
    final RaceDriver raceDriver = new RaceDriver(1, "Bob", car);
    em.persist( engine );
    em.persist( raceDriver );

    em.getTransaction().commit();

    em.clear();

    em.getTransaction().begin();

    final RaceDriver raceDriverFind = em.find( RaceDriver.class, 1);
    final Car carFind = raceDriverFind.getCar();

    //check, that at the moment the engine exists
    Assert.assertNotNull(carFind.getEngine());

    //update parent entity
    raceDriverFind.setName("Ted");
    //update the embeddable
    car.setColor("green");
    //orphan the engine object
    car.setEngine( null );

    em.getTransaction().commit();
```

Trace:
```
    UPDATE RaceDriver  SET name = ?  WHERE id = ?
[params=(String) Ted, (int) 1]
```

The issue is that OpenJPA is not updating the embeddable values on transaction commit. Also, OpenJPA is not removing the orphaned Engine reference.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)