不可能在一个字段中存储多个值。将它们存储在单个字段中的原因是什么?
一种方法可以是使用String类型的字段,然后在所有内容之间添加一个逗号分隔的列表,并在getter和setter中联接/分解:
private String vals;public setVals(int vals[]){ // this.vals = Iterate vals[] and create a comma separated string}public int[] getVals(){ // vals.split(",") to get a list of Strings, then typecast/parse them to ints before returning}使用
@ElementCollection注释并
@CollectionTable控制映射需要一个单独的表来存储值。
@ElementCollectionprivate Collection<Integer> integers;
在http://en.wikibooks.org/wiki/Java_Persistence/ElementCollection上了解有关元素集合的更多信息。



