[英]Getting a org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: Authors after using @ElementCollection
I am trying to persist collection of string for an Entity.我正在尝试为实体保留字符串集合。 To be more specific here is my Entity:
更具体地说,这里是我的实体:
@Entity
@Table(name = "AUTHOR")
public class Author{
//Other fields associated with author
@ElementCollection
@CollectionTable(name = "AUTHOR_PHONE_NUMBER", joinColumns = @JoinColumn(name = "author_id"))
@Column(name="phone_number")
private Set<String> phoneNumbers;
//Constructors
//Getters & Setters
}
However, when I build and run the code, I am getting following exceptions:但是,当我构建并运行代码时,出现以下异常:
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: AUTHOR for columns: [org.hibernate.mapping.Column(phone_number)]
I am seeing many questions similar to this on this platform but all those involve OneToMany mapping to persist collections.我在这个平台上看到许多与此类似的问题,但所有这些问题都涉及 OneToMany 映射以持久化 collections。
The list phoneNumbers should be @OneToMany , @ManyToMany (this depends from AUTHOR_PHONE_NUMBER table) annotation, replacing @CollectionTable.列表 phoneNumbers 应该是@OneToMany , @ManyToMany (这取决于 AUTHOR_PHONE_NUMBER 表)注释,替换 @CollectionTable。
the configuration must be same with @JoinColumn annotation.配置必须与@JoinColumn注释相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.