Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
2.2.2
-
None
-
None
Description
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 { @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.