Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2874

Embeddable objects are not updated and orphaned references removed

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.2.2
    • None
    • jpa
    • 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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            dazeydev Will Dazey
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: