I have a field aliases of type java.util.Set in one Entity. This Set doesn’t denote any relationship to an Entity.
-
How can I store this
aliasesfield through JPA? -
How this field get stored in database? I think that for the database, this field is a multi-valued attribute.
JPA 1.0 doesn’t support collections of basic types so you’ll have to either:
@OneToMany~or~Setstored in a BLOB (as aSerializable) ~or~@Transientand use another getter/setter to store it using a custom string representation (using a seperator) ~or~@CollectionOfElementsannotation).Solution #1 would be the cleanest portable solution. Solution #2 can lead to some troubles on upgrades. Solution #3 is a ugly workaround for #2. Solution #4 is clean but non portable.
In JPA 2.0, there is the
@ElementCollectionannotation for this use case (this is of course the ideal solution).Depending on the chosen implementation, it may be in a BLOB, in a VARCHAR, in another table.