可使用在实体中使用两次的自定义用户类型进行嵌入



我在实体RTask中使用了两次@Embeddable REmbeddedReference。此可嵌入对象包含 QName 属性,其类型定义为 org.hibernate.usertype.UserType

@Embeddable
public class REmbeddedReference implements Serializable {
    private String targetOid;
    private String description;
    private String filter;
    private RContainerType type;
    private QName relation;
    @Columns(columns = {
            @Column(name = "relation_namespace"),
            @Column(name = "relation_localPart")
    })
    public QName getRelation() {        return relation;    }
    @Column(length = 36, insertable = true, updatable = true, nullable = true)
    public String getTargetOid() {        return targetOid;    }
    @Type(type = "org.hibernate.type.TextType")
    public String getDescription() {        return description;    }
    @Enumerated(EnumType.ORDINAL)
    public RContainerType getType() {        return type;    }
    @Type(type = "org.hibernate.type.TextType")
    public String getFilter() {        return filter;    }
    ...setters...
}

RTask看起来像这样:

@Entity
@ForeignKey(name = "fk_task")
public class RTask extends RObject {
    private REmbeddedReference objectRef;
    private REmbeddedReference ownerRef;
    ...other fields...
    @Embedded
    public REmbeddedReference getObjectRef() {
        return objectRef;
    }
    @Embedded
    public REmbeddedReference getOwnerRef() {
        return ownerRef;
    }
    ...other methods...
}

在启动过程中,我得到: Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.evolveum.midpoint.repo.sql.data.common.RTask column: relation_namespace (should be mapped with insert="false" update="false")

我试图更新我的命名策略,方法逻辑列名称,它生成了objectRef_relation_namespace和ownerRef_relation_namespace。但后来我得到: Caused by: org.hibernate.DuplicateMappingException: Table [m_task] contains phyical column name [relation_namespace] represented by different logical column names: [objectRef_relation_namespace], [ownerRef_relation_namespace]

您知道如何正确映射REmbeddedReference中的属性relation吗?

解决方案:

@AttributeOverride(name="relation.namespace", column=@Column(name="object_namespace")
@AttributeOverride(name="relation.localPart", column=@Column(name="object_localpart")
@Embedded
public REmbeddedReference getObjectRef() {
    return objectRef;
}
@AttributeOverride(name="relation.namespace", column=@Column(name="owner_namespace")
@AttributeOverride(name="relation.localPart", column=@Column(name="owner_localpart")
@Embedded
public REmbeddedReference getOwnerRef() {
    return ownerRef;
}

没用。我不得不将QName类型实现从 CompositeUserType 更改为另一个可嵌入的实体RQName该实体REmbeddedReference该实体表示此属性。

相关内容

  • 没有找到相关文章

最新更新