Mig*_*ing 16 java hibernate jpa composite-key
是否可以在普通的JPA或JPA + Hibernate扩展中声明一个复合键,其中复合键的一个元素是一个序列?
这是我的复合类:
@Embeddable
public class IntegrationEJBPk implements Serializable {
//...
@ManyToOne(cascade = {}, fetch = FetchType.EAGER)
@JoinColumn(name = "APPLICATION")
public ApplicationEJB getApplication() {
return application;
}
@Column(name = "ENTITY", unique = false, nullable = false, insertable = true, updatable = true)
public String getEntity() {
return entity;
}
@GeneratedValue(strategy = GenerationType.AUTO, generator = "INTEGRATION_ID_GEN")
@SequenceGenerator(name = "INTEGRATION_ID_GEN", sequenceName = "OMP_INTEGRATION_CANONICAL_SEQ")
@Column(name = "CANONICAL_ID", unique = false, nullable = false, insertable = true, updatable = true)
public String getCanonicalId() {
return canonicalId;
}
@Column(name = "NATIVE_ID", unique = false, nullable = false, insertable = true, updatable = true)
public String getNativeId() {
return nativeId;
}
@Column(name = "NATIVE_KEY", unique = false, nullable = false, insertable = true, updatable = true)
public String getNativeKey() {
return nativeKey;
}
//...
}
Run Code Online (Sandbox Code Playgroud)
我已经提供的值application,entity,nativeId和nativeKey.我想构建一个如下所示的实体:
IntegrationEJB i1 = new IntegrationEJB();
i1.setIntegrationId(new IntegrationEJBPk());
i1.getIntegrationId().setApplication(app1);
i1.getIntegrationId().setEntity("Entity");
i1.getIntegrationId().setNativeId("Nid");
i1.getIntegrationId().setNativeKey("NK");
Run Code Online (Sandbox Code Playgroud)
当我打电话时em.persist(i1),我希望canonicalId生成并插入集成.
这可能吗?如果是这样,那简单的方法是什么?(我不想使用应用程序提供的密钥或本机sql).
| 归档时间: |
|
| 查看次数: |
14293 次 |
| 最近记录: |