Hi there,
I've created 2 classes in which I have a collection of elements. With one class there is no problem, with the other I get an exception that Hibernate can not determine the type of the collection. Could it have something to do with the fact that one is bi-directional while the other is not? The bi-directional one works by the way.
Here is the code of the classes (slimmed down):
The first one works just fine:
Code:
@Entity
@SequenceGenerator(name = "SEQ_DATAITEM", sequenceName = "dataitem_sequence")
public class DataItem implements Comparable<DataItem>, Serializable, DataChangeListener {
private static final long serialVersionUID = 1L;
private Long id;
private DataItem parent;
private final UniqueList<DataItem> subData = new UniqueList<DataItem>();
protected DataItem() {
super(); // Used by Hibernate
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_DATAITEM")
public Long getId() {
return id;
}
protected void setId(Long id) {
this.id = id;
}
@ManyToOne
public DataItem getParent() {
return parent;
}
protected void setParent(DataItem parent) {
this.parent = parent;
}
@OneToMany(cascade = CascadeType.ALL, mappedBy = "parent")
public List<DataItem> getAllSubData() {
return subData;
}
protected void setAllSubData(List<DataItem> subData) {
this.subData.clear();
this.subData.addAll(subData);
}
}
This one generates the error:
Initial SessionFactory creation failed.org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: PostureAspects, for columns: [org.hibernate.mapping.Column(accents)]
Code:
@Entity
@SequenceGenerator(name = "SEQ_POSTURE_ASPECTS", sequenceName = "postureAspects_sequence")
public class PostureAspects extends PersistentObject implements MonitoreableObjectChangeListener {
private UniqueList<DataItem> accents = new UniqueList<DataItem>();
PostureAspects() {
}
@Override
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_POSTURE_ASPECTS")
public Long getId() {
return super.getId();
}
@OneToMany
@JoinTable(name = "ExerciseAccents", joinColumns = @JoinColumn(name = "postureAspects_id"), inverseJoinColumns = @JoinColumn(name = "accent_id"))
protected void setAccents(Set<DataItem> accents) {
this.accents.clear();
this.accents.addAll(accents);
}
/**
* @return The accents
*/
public Set<DataItem> getAccents() {
return accents;
}
}
At first I thought that it might have something to do with the fact that UniqueList is not a collection supported by Hibernate but then things should not work in the first class either.
Any help with this would be greatly appreciated.
Cheers,
Stef