简体   繁体   English

合并现有对象不会更新数据库中更改的@Embedded

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

I am using the Amdatu implementation of Eclipselink for OSGI compatibility. 我正在使用Eclipselink的Amdatu实现来实现OSGI兼容性。

Can anyone spot why this is not working? 谁能发现为什么这行不通?

The class below is defined as an Entity and should be persisted. 下面的类定义为Entity,并且应该保留。 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. 每次对Ptz2PlPalletUnloadOrder进行更新时, OrderRepoImpl中的save方法都会将持久性订单与更新的版本合并,其中Ptz2PlPalletUnloadDefinition defOrderState orderState已更改。

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. 无论如何,我可以使用em.merge方法更新数据库中的orderState,但是我无法更新BD中的@Embedded def Object。 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. 合并对象时,不会引发任何异常,log4j包含在问题的底部。

Ptz2PlPalletUnloadOrder 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 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 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. 因此,人们希望数据库已经更新,但是当Ptz2PlPalletUnloadOrder要更新字段是嵌入式对象时,不会发生这种不幸。

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. 我已经在amdatu-jpa测试案例中重现了这一点。

Found a similar question on the EclipseLink forum https://www.eclipse.org/forums/index.php/t/474144/ 在EclipseLink论坛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 要禁用,请在persistence.xml中添加以下属性

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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