Hi,
I just switched from a java.util.List to a java.util.Stack and getting now this error message:
Quote:
org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements:"
Code:
/** List to keep data about historical changes */
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@IndexColumn(name = "pos", base = 1)
private Stack<ModificationHistoryElement> history;
Even removing @IndexColumn makes no difference.
Cause Stack implements java.util.Collection, this message makes no sense, or?
What's wrong?
Changing it to
Code:
/** List to keep data about historical changes */
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@IndexColumn(name = "pos", base = 1)
private Collection<ModificationHistoryElement> history;
Code:
this.history = new Stack<ModificationHistoryElement>();
Solves the problem, but it looses the Stack methods, which forces unnecessary casts, which makes the code quite ugly.
Then I would prefer a normal list and would use list.get(list.size()-1) to get the last element. Also ugly, but at least less vulnerable against ClassCastExceptions.
It seems that hibernate doesn't know neither supports stacks.
Thank you.
Greetings Michael