Tag: composite key

Hibernate外键与复合主键的一部分

我必须使用Hibernate并且我不太确定如何解决这个问题,我有2个表与1..n关系,如下所示: ——- TABLE_A ——- col_b(pk) col_c(pk) [其他领域] ——- 表-B ——- col_a(pk) col_b(pk)(fk TABLE_A.col_b) col_c(fk TABLE_A.col_c) [其他领域] 如何使用Hibernate进行管理? 我不知道如何声明包含主键部分的外键。 我的数据库模式是从Hibernate模型生成的。

Embeddable类中的外键映射

我正在使用eclipselink进行JPA 。 我有一个实体,它有一个由两个字段组成的复合键 。 以下是我的可嵌入主键类’字段(成员)。 @Embeddable public class LeavePK { @ManyToOne(optional = false) @JoinColumn(name = “staffId”, nullable = false) private Staff staff; @Temporal(TemporalType.TIMESTAMP) private Calendar date; //setters and getters } 我的实体将保留与员工相关的休假数据,因此我尝试将员工对象和离开日期结合起来以生成组合键。 除了我的逻辑,它不允许我在嵌入类中有一个外键映射。 当我尝试使用JPA工具 – >从实体生成表时 ,它会给出如下错误,这解释了,但我没有得到它。 org.eclipse.persistence.exceptions.ValidationException Exception Description: The mapping [staff] from the embedded ID class [class rs.stapp.entity.LeavePK] is an invalid mapping for this […]

使用@EmbeddedId进行映射时出现Eclipse错误

我有一个具有复合键的实体,所以我使用@Embeddable和@EmbeddedId注释。 Embeddable类看起来像这样: @Embeddable public class DitaAdminAccountSkillPK implements Serializable { @ManyToOne @JoinColumn(name = “admin_id”) private DitaAdmin admin; @ManyToOne @JoinColumn(name = “account_id”) private DitaAccount account; //constructor, getters, setters… } 以及使用它的实体: @Entity public class DitaAdminAccountSkill { @EmbeddedId private DitaAdminAccountSkillPK id; //constructor, getters, setters… } 现在我想在另一个实体中映射实体,如下所示: @OneToMany(fetch = FetchType.LAZY, mappedBy = “id.admin”) private List accountSkills; 注意mappedBy =“id.admin” ,它使用DitaAdminAccountSkill的id字段引用DitaAdminAccountSkillPK中的 admin字段。 […]

JPA复合键+序列

在普通的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 = […]

JPA表有2个主键字段

我有一个只包含2个字段的表。 该表具有由这两个字段形成的复合PK。 使用Netbeans从数据库创建实体bean时,实体bean不会像其他具有2个以上字段的表一样自动创建。 所以我想我需要自己创建实体bean。 创建此实体bean的最佳做法是什么? 是否必须包含COMPOSITE KEY对象?

如何在复合键中使用生成的值?

我有两个类documentlog和documentversion(主键:int doc_id和int docVersionID),具有多对一关系。 我使用了一个名为CompundKey的复合键类来管理复合主键。 我需要自动增加docversionID,但我无法做到这一点。 在这方面你能帮我吗? @Entity @Table(name = “Documentversion”, schema = “DocumentManagement”) public class DocumentVersion implements Serializable { private CompoundKey id; private List documentLog; @OneToMany(mappedBy=”documentVersion”, targetEntity=DocumentLog.class, cascade ={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH}) public List getDocumentLog() { return documentLog; } public void setDocumentLog(List documentLog) { this.documentLog = documentLog; } @EmbeddedId @AttributeOverride(name=”doc_Id”, column=@Column(name=”doc_Id”) ) public CompoundKey getId() { […]

Hibernate问题:外键必须与引用的主键具有相同数量的列

目标:我想将ImportJob中的importJobId作为分配表的id的外键,这样当我们有importJobId然后只有我们可以在分配时没有Job而没有任何分配。 ImportJob表的复合主键为[ORGID,IMPORTJOBTYPE],我试图在hibernate中创建外键关系 在Allocation.hbm.xml中没有运行并收到错误消息: Foreign key (FKB29B5F7366007086:ALLOCATIONS [importjobid])) must have same number of columns as the referenced primary key (IMPORTJOBMANAGMENT [ORGID,IMPORTJOBTYPE]) 这是我的ImportJob.hbm.xml文件 以下是bean类供参考: public class AllocationBean extends WorkbenchBeanBase { private static final Logger log = Logger.getLogger(AllocationBean.class); private Float allocations; private String importJobType; private long id; private long orgId; } public class ImportJobManagment implements Serializable { private […]

@OneToMany和复合主键?

我正在使用带有注释的Hibernate(在spring中),并且我有一个对象,它有一个有序的,多对一的关系,一个子对象有一个复合主键,其中一个组件是一个外键回到父对象的id。 结构看起来像这样: +=============+ +================+ | ParentObj | | ObjectChild | +————-+ 1 0..* +—————-+ | id (pk) |—————–| parentId | | … | | name | +=============+ | pos | | … | +================+ 我尝试了各种注释组合,但似乎都没有。 这是我能够提出的最接近的: @Entity public class ParentObject { @Column(nullable=false, updatable=false) @Id @GeneratedValue(generator=”…”) private String id; @OneToMany(mappedBy=”parent”, fetch=FetchType.EAGER, cascade={CascadeType.ALL}) @IndexColumn(name = “pos”, base=0) […]

hibernate复合键

是否有必要将composite-id映射到类? 可以这样吗? 或应该是 如果有必要,如果我们有复合键,那么该类应该实现equals()和override()方法?