我想使用注释将电子邮件保留在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)]
有什么想法吗?