[jira] [Updated] (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] [Updated] (OPENJPA-2874) Embeddable objects are not updated and orphaned references removed

Mark Struberg (Jira)

     [ https://issues.apache.org/jira/browse/OPENJPA-2874?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Will Dazey updated OPENJPA-2874:
--------------------------------
    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:
{code:java}
@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;
}
{code}

Test:
{code:java}
    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();
{code}

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

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

  was:
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:
{code:java}
@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;
}
{code}

Test:
{code:java}
    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();
{code}

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

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


> 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
>            Priority: Minor
>
> 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:
> {code:java}
> @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;
> }
> {code}
> Test:
> {code:java}
>     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();
> {code}
> Trace:
> {code:sql}
>     UPDATE RaceDriver  SET name = ?  WHERE id = ?
> [params=(String) Ted, (int) 1]
> {code}
> 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)