gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:03:51 24 4
gpt4 key购买 nike

我正在使用 Eclipselink 的 Amdatu 实现来实现 OSGI 兼容性。

有人能找出为什么这不起作用吗?

下面的类被定义为实体并且应该被持久化。每次更新 Ptz2PlPalletUnloadOrder 时,OrderRepoImpl 中的 save 方法会将持久订单与更新版本合并,其中 Ptz2PlPalletUnloadDefinition defOrderState orderState 已更改。

无论如何,我可以使用 em.merge 方法更新数据库中的 orderState,但无法更新 BD 中的 @Embedded def 对象。高度推荐更新而不在数据库中创建新行。

合并对象时不会引发异常,log4j 包含在问题的底部。

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

持久化类。

@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;
}
}

通过该方法制动时,结果值是正确的。因此,人们会期望数据库已更新,但当 Ptz2PlPalletUnloadOrder 的待更新字段是嵌入对象时,这种不幸的情况不会发生。

日志

[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

最佳答案

我已在 amdatu-jpa 测试用例中重现了此内容。

在 EclipseLink 论坛上发现类似问题 https://www.eclipse.org/forums/index.php/t/474144/

禁用编织可以解决我创建的测试中的问题。要禁用,请将以下属性添加到 persistence.xml

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

关于java - 合并现有对象不会更新数据库中更改的@Embedded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35294552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com