JPA复合键+序列 [英] JPA Composite Key + Sequence

查看:99
本文介绍了JPA复合键+序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在纯JPA或JPA + Hibernate扩展中,是否可以声明组合键,其中组合键的元素是序列?

这是我的合成class:

  @Embeddable 
public class IntegrationEJBPk实现了Serializable {

// .. 。


@ManyToOne(cascade = {},fetch = FetchType.EAGER)
@JoinColumn(name =APPLICATION)
public ApplicationEJB getApplication(){
返回应用程序;


$ b @Column(name =ENTITY,unique = false,nullable = false,insertable = true,updatable = true)
public String getEntity ){
返回实体;
}

@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(){
返回nativeId;


@Column(name =NATIVE_KEY,unique = false,nullable = false,insertable = true,updatable = true)
public String getNativeKey(){
返回nativeKey;
}

// ...
}

我已经为应用程序实体 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);

当我调用 em.persist(i1 ),我希望生成 canonicalId 并且插入集成。



这可能吗?如果是这样,那么简单的方法是什么? (我更喜欢不使用应用程序提供的键或本机sql)。 我相信这对于普通的JPA来说是不可能的。


Is it possible in plain JPA or JPA+Hibernate extensions to declare a composite key, where an element of the composite key is a sequence?

This is my composite class:

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

    //...
}

I already supply the values for application, entity, nativeId and nativeKey. I want to construct an entity like the one below:

IntegrationEJB i1 = new IntegrationEJB();
i1.setIntegrationId(new IntegrationEJBPk());
i1.getIntegrationId().setApplication(app1);
i1.getIntegrationId().setEntity("Entity");
i1.getIntegrationId().setNativeId("Nid");
i1.getIntegrationId().setNativeKey("NK");

And when I call em.persist(i1), I want that the canonicalId is generated and the integration is inserted.

Is this possible? If so, what's the simple way? (I prefer not to use application-provided keys or native sql).

解决方案

I believe that this is not possible with plain JPA.

这篇关于JPA复合键+序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆