java - JPA 如何持久化地图>
问题描述
我想使用注释将电子邮件保存在 Oracle 数据库中。我的Email
班级有一个 Map 属性recipients
,它按 TO、CC 和 BCC 分组,并有一组电子邮件地址作为值:
@Entity
@Table(name="EMAIL")
public class Email {
@Id
@SequenceGenerator(name="emailSeq", sequenceName="EMAIL_SEQ", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="emailSeq")
@Column(name="id")
private Long id = null;
@ElementCollection(targetClass=Set.class)
@CollectionTable(name = "emailrecipients", joinColumns=@JoinColumn(name="email_id"))
@MapKeyEnumerated(EnumType.STRING)
@Column(name="address")
private Map<RecipientType, Set<String>> recipients = new HashMap<RecipientType, Set<String>>();
...
}
public enum RecipientType {
TO,
CC,
BCC
}
我的数据库如下所示:
CREATE TABLE email
( id number(10) NOT NULL,
...
CONSTRAINT email_pk PRIMARY KEY (id)
);
CREATE TABLE emailrecipients
( email_id number(10) NOT NULL,
--Addresstypes: "TO", "CC", "BCC"
addresstype varchar2(50) NOT NULL,
address varchar2(100) NOT NULL,
CONSTRAINT fk_emailrecipients_email FOREIGN KEY (email_id) REFERENCES email(id)
);
我无法正确进行映射,并且出现以下错误:
org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: emailrecipients, for columns: [org.hibernate.mapping.Column(address)]
有任何想法吗?
解决方案
推荐阅读
- c# - 如何在 Azure DevOps 上为发布服务器项目而不是客户端的 Blazor WebAssembly 托管应用程序创建构建管道?
- r - 条形图 - R 中的直方图
- php - php,如何将 int 打包为签名的 64 位 little-endian 字符串?
- json - 字符串列表的 Spring Boot 输入验证仅返回第一个无效值
- swift - 如何添加长度不同的两个数组的值?
- c# - 如何统一更新运行时的图像?
- asp.net - 如何为具有相同根文件夹的 2 个域设置 web.config
- html - Chrome / Windows 中的 CSS 3D 变换交叉点故障
- firebase - Firebase 数据库保护项目所有者的数据
- python - 在 Peewee 中禁用缓存