persistence@glassfish.java.net

Re: Can't initialize a collection field?

From: Tom Ware <tom.ware_at_oracle.com>
Date: Fri, 05 May 2006 10:15:18 -0400

Hi Marina,

  This looks like it may be a bug related to the use of HashSet. Please
enter an issue in the Issue Tracker.

Thanks,
Tom

Marina Vatkina wrote:

>Tom,
>
>Am i doing something wrong?
>
>If I change in Java SE persistence example (from
>https://glassfish.dev.java.net/javaee5/persistence/persistence-example.html)
>
>from:
>private Collection<Order> orders = null;
>
>to:
>private Collection<Order> orders = new HashSet<Order>();
>
>I get the following exception, which does not depend on field or property based
>access type:
>
>[TopLink Info]: 2006.05.04 03:41:34.992--ServerSession(19739141)--TopLink,
>version: Oracle TopLink Essentials - 2006.4 (Build 060412)
>[TopLink Info]: 2006.05.04
>03:41:37.658--ServerSession(19739141)--file:/faith4/gf/glassfish/www/javaee5/persistence/ex1/classes-pu1
>login successful
>Exception in thread "main" javax.persistence.EntityExistsException:
>Exception Description: The mapping for the attribute [orders] uses transparent
>indirection so the attribute [orders] must be initialized to an appropriate
>container. Currently the value is [[]].
> - JDK 1.1.x: an instance of IndirectList, IndirectMap or Hashtable, or one of
>their subclasses.
> - JDK 1.2 or higher: an instance of an implementor of Collection or Map.
>Mapping: oracle.toplink.essentials.mappings.OneToManyMapping[orders]
>Descriptor: RelationalDescriptor(entity.Customer --> [DatabaseTable(CUSTOMER)])
> at
>oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:153)
> at client.Client.testInsert(Client.java:82)
> at client.Client.main(Client.java:49)
>Caused by: Exception [TOPLINK-150] (Oracle TopLink Essentials - 2006.4 (Build
>060412)): oracle.toplink.essentials.exceptions.DescriptorException
>Exception Description: The mapping for the attribute [orders] uses transparent
>indirection so the attribute [orders] must be initialized to an appropriate
>container. Currently the value is [[]].
> - JDK 1.1.x: an instance of IndirectList, IndirectMap or Hashtable, or one of
>their subclasses.
> - JDK 1.2 or higher: an instance of an implementor of Collection or Map.
>Mapping: oracle.toplink.essentials.mappings.OneToManyMapping[orders]
>Descriptor: RelationalDescriptor(entity.Customer --> [DatabaseTable(CUSTOMER)])
> at
>oracle.toplink.essentials.exceptions.DescriptorException.indirectContainerInstantiationMismatch(DescriptorException.java:658)
> at
>oracle.toplink.essentials.internal.indirection.TransparentIndirectionPolicy.validateAttributeOfInstantiatedObject(TransparentIndirectionPolicy.java:368)
> at
>oracle.toplink.essentials.mappings.ForeignReferenceMapping.getAttributeValueFromObject(ForeignReferenceMapping.java:296)
> at
>oracle.toplink.essentials.mappings.CollectionMapping.cascadeRegisterNewIfRequired(CollectionMapping.java:237)
> at
>oracle.toplink.essentials.internal.descriptors.ObjectBuilder.cascadeRegisterNewForCreate(ObjectBuilder.java:1241)
> at
>oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:3175)
> at
>oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:149)
> ... 2 more
>
>
>
>thanks,
>-marina
>
>