It is not possible to store multiple values in a single field. Whats the reason behind storing them in a single field?
A way could be to use a field of type String and add all integers there in a comma separated list and join/explode in getters and setters:
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
}
Using the @ElementCollection
annotation and @CollectionTable
to control the mappings requires a separate table to store the values in.
@ElementCollection
private Collection<Integer> integers;
Read more about element collections on on http://en.wikibooks.org/wiki/Java_Persistence/ElementCollection
Similar question here Does JPA @ElementCollection annotation always produce an one-to-many relationship?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…