为什么JPA映射属性不能是LinkedHashset? [英] Why cannot a JPA mapping attribute be a LinkedHashset?

查看:84
本文介绍了为什么JPA映射属性不能是LinkedHashset?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题的激励,我尝试更改以下内容:

Motivated by this question, I've tried to change the following:

 @ManyToMany(cascade={CascadeType.REMOVE, CascadeType.MERGE})
private Set<Expression> exps = new LinkedHashSet<Expression>();

至:

 @ManyToMany(cascade={CascadeType.REMOVE, CascadeType.MERGE})
    private LinkedHashSet<Expression> exps = new LinkedHashSet<Expression>();

但是,这样的移动导致:

However, such a move results in:

Exception [EclipseLink-1] (Eclipse Persistence Services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions.DescriptorException

异常描述:[exps]属性未声明为ValueHolderInterface类型,但其映射使用了间接寻址。
映射:org.eclipse.persistence.mappings.ManyToManyMapping [exps]
描述符:RelationalDescriptor(com.mysimpatico.memoplatform.persistence.entities.Meaning-> [DatabaseTable(MEANING)])

Exception Description: The attribute [exps] is not declared as type ValueHolderInterface, but its mapping uses indirection. Mapping: org.eclipse.persistence.mappings.ManyToManyMapping[exps] Descriptor: RelationalDescriptor(com.mysimpatico.memoplatform.persistence.entities.Meaning --> [DatabaseTable(MEANING)])

我应该如何在JPA2中实现所需的行为?

How am I supposed in JPA2 to achieve the desired behavior?

推荐答案

仅JPA中允许将标准接口类型作为属性类型。为什么要更改属性的类型?使用原始定义,基础集合仍然是您的自定义类型。

Only the standard interfaces types are allowed as attribute types in JPA. Why are you changing the type of the attribute? With the original definition the underlying collection is still your custom type.

这篇关于为什么JPA映射属性不能是LinkedHashset?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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