Hibernate MappingException转换为ElementCollection

时间:2013-01-09 16:03:10

标签: hibernate collections hibernate-onetomany

我在重构代码时遇到问题,使用JPA ElementCollection而不是弃用的CollectionOfElements。 我看到以下堆栈跟踪:

  

org.hibernate.MappingException:无法确定类型:java.util.Set,在表:UserFilter,用于列:[org.hibernate.mapping.Column(element)]       在org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:292)       在org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:276)       在org.hibernate.mapping.Property.isValid(Property.java:207)       在org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:458)       在org.hibernate.mapping.JoinedSubclass.validate(JoinedSubclass.java:63)       在org.hibernate.cfg.Configuration.validate(Configuration.java:1149)       在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1334)       在org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)

UserFilter中更改的代码如下:

//@CollectionOfElements
@ElementCollection(targetClass = String.class)
@CollectionTable(name="UserFilter_orgUnits", joinColumns=@JoinColumn(name="UserFilter_FILTER_ID"))
@Column(columnDefinition = "varchar(255)", name="element")
private Set<String> orgUnits = new HashSet<String>();

我指定连接表名称和列名称以实现向后兼容。

0 个答案:

没有答案