eclipselink icon indicating copy to clipboard operation
eclipselink copied to clipboard

Update JPQL queries for Embeddables don't include all fields

Open dazey3 opened this issue 2 years ago • 0 comments

Description: When executing a JPQL Update query, EclipseLink does not update all Embeddable fields and doesn't translate the embeddable to the correct fields

Classes:

@Entity
public class House {
    @Id public String parcelId;
    @Embedded public Garage garage;
}

@Embeddable
public class Garage {
    public int area;
    public String type;
}

----Failing Tests----

Test 1:

    Query query = em.createQuery("UPDATE House o SET o.garage=?2 WHERE (o.parcelId=?1)");
    query.setParameter(1, "TestEmbeddable-304-3655-30");
    query.setParameter(2, null);
    query.executeUpdate();

SQL:

UPDATE HOUSE SET AREA = ? WHERE (PARCELID = ?)
	bind => [null, TestEmbeddable-304-3655-30]

Test 2:

    Query query = em.createQuery("UPDATE House o SET o.garage=?2 WHERE (o.parcelId=?1)");
    query.setParameter(1, "TestEmbeddable-304-3655-30");
    query.setParameter(2, new Garage(100, "Detached"));
    query.executeUpdate();

SQL:

UPDATE HOUSE SET AREA = ? WHERE (PARCELID = ?)
	bind => [test..jpa.web.Garage@d4602a, TestEmbeddable-304-3655-30]

----Passing Tests----

Test 1:

    em.getTransaction().begin();
    House findHouse = em.find(House.class, h3.parcelId);
    findHouse.setGarage(null);
    em.getTransaction().commit();

SQL:

UPDATE HOUSE SET AREA = ?, TYPE = ? WHERE (PARCELID = ?)
	bind => [null, null, TestEmbeddable-304-3655-69]

Test 2:

    em.getTransaction().begin();
    House findHouse = em.find(House.class, h3.parcelId);
    findHouse.setGarage(new Garage(100, "Detached"));
    em.getTransaction().commit();

SQL:

UPDATE HOUSE SET GARAGEAREA = ?, GARAGETYPE = ? WHERE (PARCELID = ?)
	bind => [100, Detached, TestEmbeddable-304-3655-69]

dazey3 avatar Mar 31 '23 17:03 dazey3