Same here ... and in a way obvious. How should Hibernate now the length if it is omitting the null elements / values.
A simple workaround to access individual elements in the array is still possible:
Code:
@Entity
public class Foo {
@CollectionOfElements
@IndexColumn(name="index", base=0)
@Column(name = "long_value")
private Long[] longs;
@Basic
private int length;
public void setLongs(Long[] longs) {
this.longs = longs;
this.length = longs.length;
}
public long getModification(int pos) {
if (pos >= getLongs().length && pos <= getLength()) {
return 0;
}
Long mod = getModifications()[pos];
if(mod == null) return 0;
return mod;
}
//private since this is not returning the correct array...
private Long[] getLongs() {
return longs;
}
public int getLength() {
return length;
}
}
Surely, if one is interested to get the whole array instead of individual elements then the same approach can be applied ...
Maybe this helps ...