【发布时间】:2021-04-10 18:18:09
【问题描述】:
问题是使用 Hibernate 持久化以下类。
Public class Album{
Private int albumid;
Private String aname;
Private Map<String,List<String>> photos;
}
我试过了
@Entity
public class Album {
@Id
private int albumId;
@Column(name= "Album_Name")
private String aname;
@ElementCollection
@MapKeyColumn(name= "Event_Name")
@Column(name="Values")
private Map<String, List<String>> photos;
但它显示错误,例如
Exception in thread "main" org.hibernate.MappingException: Could not determine type for: java.util.List, at table: Album_photos, for columns: [org.hibernate.mapping.Column(Values)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:310)
at org.hibernate.mapping.Collection.validate(Collection.java:315)
at org.hibernate.mapping.IndexedCollection.validate(IndexedCollection.java:89)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1362)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1849)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
at com.wipro.Insert.main(Insert.java:17)
【问题讨论】:
-
没有这样的注释,你必须为照片创建新的
class并使用像@OnetoMany这样的休眠映射,这将创建2个表。
标签: java hibernate-mapping hibernate-annotations