persistence@glassfish.java.net

Re: field of type List<String>

From: Sanjeeb Kumar Sahoo <Sanjeeb.Sahoo_at_Sun.COM>
Date: Fri, 02 Mar 2007 07:31:46 +0530

Hi Jeff,

jeff wrote:
> okay ... to be clear,
>
> 1. i had expected List<String> to just work. it's a bug that it doesn't
*No*, List<String> is *not* expected to work, as it is not a
Serializable type. Section #2.1 of the JPA spes says the following:

/The persistent fields or properties of an entity may be of the
following types: Java primitive types;
java.lang.String; other Java serializable types (including wrappers of
the primitive types,
java.math.BigInteger, java.math.BigDecimal, java.util.Date,
java.util.Calendar[7], java.sql.Date, java.sql.Time, java.sql.Timestamp,
user-defined serializable types, byte[], Byte[], char[], and
Character[]); enums; entity
types and/or collections of entity types; and embeddable classes (see
section 2.1.5).
/
See also section #2.1.6 which says the behavior when no annotation is
present:

/ If the type of the field or property is one of the following, it is
mapped in the same way as it
would if it were annotated as Basic: Java primitive types, wrappers of
the primitive types,
java.lang.String, java.math.BigInteger, java.math.BigDecimal,
java.util.Date, java.util.Calendar, java.sql.Date, java.sql.Time,
java.sql.Timestamp, byte[], Byte[], char[], Character[], enums, any other
type that implements Serializable. See Sections 9.1.18 through 9.1.21.
It is an error if no annotation is present and none of the above rules
apply./

>
> 2. @Basic List<String> is not expected to work, as the type must be
> serializable if @Basic is present
Does not matter if @Basic is present or not. It is never expected to work.
>
> 3. @Basic ArrayList should work also.
Yes.
>
> 3b. using ArrayList should also work (as it does), as @Basic is
> optional for serializable types
Yes. @Basic is also optional for some other types as mentioned in
section #2.1.6.

Thanks,
Sahoo