简体   繁体   中英

Merging an existing object does not update the changed @Embedded in the database

I am using the Amdatu implementation of Eclipselink for OSGI compatibility.

Can anyone spot why this is not working?

The class below is defined as an Entity and should be persisted. Every time an update is made to the Ptz2PlPalletUnloadOrder , the save method in OrderRepoImpl merges the persisted order with an updated version where the Ptz2PlPalletUnloadDefinition def or the OrderState orderState has been changed.

Anyways, I am able to update the orderState in the database using the em.merge method, but I cannot update the @Embedded def Object in the BD. Updating without making a new row in the database is highly preferred.

When merging the object no exception is thrown, the log4j is included at the bottom of the question.

Ptz2PlPalletUnloadOrder

@Entity(name = Ptz2PlPalletUnloadOrder.TABLE_NAME)
@Table(name = Ptz2PlPalletUnloadOrder.TABLE_NAME)
public class Ptz2PlPalletUnloadOrder implements Order {
    public static final String TYPE = "ptz2pl.pallet.unload";
    public static final String TABLE_NAME = "order_ptz2pl_pallet_unload";

    // Order ID
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long dbId;

    @Temporal(TemporalType.TIMESTAMP)
    private Date created = new Date();

    // States
    @Enumerated(EnumType.STRING)
    private OrderState orderState = OrderState.NEW;

    @Embedded
    private Ptz2PlPalletUnloadDefinition def;
}

Ptz2PlPalletUnloadDefinition

The persisted class.

@Embeddable
public class Ptz2PlPalletUnloadDefinition {

    @Embedded
    private Station station;
    private volatile Integer agvId;
    private volatile String agvSystemName;
    @Temporal(TemporalType.TIMESTAMP)
    private Date deadLine;
    private String userId;
    private Long palletType;

    private Ptz2PlPalletUnloadDefinition() {

    }
}

OrderRepoImpl

@Transactional
@Component(provide = ManagedTransactional.class)
public class OrderRepoImpl implements OrderRepo, ManagedTransactional {

    private EntityManager em;

    @Override
    public Ptz2PlPalletUnloadOrder save(Ptz2PlPalletUnloadOrder order) {
        Ptz2PlPalletUnloadOrder result = em.merge(order);
        return result;
    }
}

When braking through this method, the result value has the correct values. So one would expect that the database has been updated, but this unfortunate does not happen when the to be updated field of Ptz2PlPalletUnloadOrder is an embedded object.

Log

[EL Finer]: 2016-02-09 15:25:32.393--ServerSession(1465675217)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--client acquired: 2038620953
[EL Finer]: 2016-02-09 15:25:32.393--UnitOfWork(769186)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--TX binding to tx mgr, status=STATUS_ACTIVE
[EL Finer]: 2016-02-09 15:25:32.394--ClientSession(2038620953)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--acquire unit of work: 769186
[EL Finest]: 2016-02-09 15:25:32.395--UnitOfWork(769186)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--Merge clone with references Ptz2PlPalletUnloadOrder [id=1, orderState=QUEUED, location=Location [stationId=10, systemName=BEING], allocatedAgvId=null, allocatedAgvSystemName=null]
[EL Finer]: 2016-02-09 15:25:37.014--UnitOfWork(769186)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--TX beforeCompletion callback, status=STATUS_ACTIVE
[EL Finer]: 2016-02-09 15:25:37.015--UnitOfWork(769186)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--begin unit of work commit
[EL Finer]: 2016-02-09 15:25:37.016--UnitOfWork(769186)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--TX afterCompletion callback, status=COMMITTED
[EL Finer]: 2016-02-09 15:25:37.017--UnitOfWork(769186)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--end unit of work commit
[EL Finer]: 2016-02-09 15:25:37.018--UnitOfWork(769186)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--release unit of work
[EL Finer]: 2016-02-09 15:25:37.019--ClientSession(2038620953)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--client released

I've reproduced this in an amdatu-jpa testcase.

Found a similar question on the EclipseLink forum https://www.eclipse.org/forums/index.php/t/474144/

Disabling weaving resolves the issue in the test I've created. To disable add the property below to persistence.xml

<property name="eclipselink.weaving" value="false"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM