persistence@glassfish.java.net

Re: field of type List<String>

From: jeff <jeffrey.blattman_at_yahoo.com>
Date: Fri, 2 Mar 2007 09:53:11 -0800 (PST)

sanjeeb, from page 19 of the jsr 220 persistence spec,

Collection-valued persistent fields and properties must be defined in terms of one of the following collection-valued interfaces regardless of whether the entity class otherwise adheres to the JavaBeans method conventions noted above and whether field or property-based access is used:

java.util.Collection, java.util.Set, java.util.List[4], java.util.Map.[5]

For collection-valued persistent properties, type T must be one of these collection interface types in the method signatures above. Generic variants of these collection types may also be used (for example, Set<Order>).

and the spec further gives the example:

private Set<PhoneNumber> phones = new HashSet();

note that Set is not serializable of course, nor are any of the required collection types above.

in the context of our discussion, how should i interpret this? the only thing i can think here is that Set<Order> works because Order is an entity, but Set<String> doesn't work because String isn't an entity.

indeed, the spec says that "collections of entity types" are persistable, but it does NOT say "collections of persistable types are persistable".

am i hitting on the root of the issue?



Sanjeeb Kumar Sahoo <Sanjeeb.Sahoo_at_Sun.COM> wrote: Hi Jeff,

jeff wrote:
> okay ... to be clear,
>
> 1. i had expected List to just work. it's a bug that it doesn't
*No*, List 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 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


 
---------------------------------
The fish are biting.
 Get more visitors on your site using Yahoo! Search Marketing.