(基于进一步测试编辑的原始问题)
基本细节:
Table Environment
PK NUMBER,
Name CHAR(3)
Table ApplicationEntity
PK NUMBER,
Name VARCHAR2(64)
Table ApplicationInstance
PK NUMBER,
ApplicationEntityFk NUMBER references ApplicationEntity(PK),
EnvironmentFk NUMBER references Environment(PK)
JPA提供程序是EclipseLink。
ApplicationInstance
是ApplicationEntity("MyApp")
的一个实例
部署到特定的Environment ("DEV","UAT","PRD")
。单个ApplicationEntity
可能会为每个ApplicationInstance
部署Environment
。
class Environment
{
private Long PK;
private String name;
@Id
@Column(name="PK")
public Long getId()
{
return PK;
}
...
}
class ApplicationInstance
{
private Environment environment;
@OneToOne
@JoinColumn(name="EnvironmentFk")
Environment getEnvironment()
{
return environment;
}
}
如果我使用虚假ApplicationInstance
创建Environment(PK=100,Name="FOO")
:
使用merge()
:由于没有此类Environment
而拒绝插入,而Environment
表正在使用新行(PK=100,Name="FOO)
进行更新。
使用persist()
抛出以下异常(已编辑):
During synchronization a new object was found through a relationship that was not marked cascade PERSIST: Environment
问题:
persist()
和merge()
?cascade MERGE
和DEFAULT
分别是开启还是关闭?