JPA @Embeddable

use*_*961 5 hibernate jpa-2.0

我正在使用@ElementCollection作为自定义对象列表

@ElementCollection
@CollectionTable(name = "choice", joinColumns = @JoinColumn(name = "itemId"))
@OrderColumn(name = "index")
private List<Choice> choices = new ArrayList<Choice>();
Run Code Online (Sandbox Code Playgroud)

我已经创建了这样的Choice类

//@Embeddable
@Table(name = "choice")
@Cacheable(false)
@Audited
public class Choice implements Serializable{
Run Code Online (Sandbox Code Playgroud)

如果我使用@Embeddable注释,我会得到 org.hibernate.MappingException: Type not supported for auditing: org.hibernate.type.ComponentType

我是JPA的新手.有什么我想念的吗?

Chr*_*ine 5

如果要使用@Embeddable,引用@Embeddable该类的字段需要具有@Embedded注释.然后,@Embedded类中的字段需要具有适当的JPA注释,因此JPA知道如何处理它们.您可能想要阅读此内容以便完全理解@Embbedable它的作用.