本文介绍了Spring JPA/Hibernate:如何在非主列上映射多态关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class B{
@Any(metaColumn = @Column(name = "ITEM_TYPE"))
@AnyMetaDef(idType = "long", metaType = "string",
        metaValues = {
                @MetaValue(targetEntity = A.class, value = "A")
        })
@Cascade( { org.hibernate.annotations.CascadeType.ALL})
@JoinColumn(name = "ITEM_ID")
private A a;
...
...
}

我正在尝试连接表A和表B where B.item_type ='A'恒定B.item_id= A.id.

它把我扔了

Caused by: org.hibernate.MappingException: Foreign key (FKi1uuph2wrvxtx66s7n7i1s09a:B [item_type,item_id])) must have same number of columns as the referenced primary key (A [id])

有关如何使用Spring JPA和Hibernate进行映射的任何帮助?

Any help on How shall i map this using spring jpa and hibernate?

推荐答案

我可以通过另一种方法来解决此问题,在该方法中,我将关联实体设置为@Transient,然后将其保存在父实体的@PostPersist调用中通过添加EntityListener类.

I was able to fix this by a alternate approach where I made the associated entity as @Transient and then I saved that transient entity on @PostPersist call from parent entity by adding an EntityListener class.

这篇关于Spring JPA/Hibernate:如何在非主列上映射多态关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 08:24