persistence@glassfish.java.net

Re: Simple collections

From: Tom Ware <tom.ware_at_oracle.com>
Date: Wed, 30 May 2007 09:04:34 -0400

Hi Aleksei,

  At the moment, the specification does not have a mapping for simple
collections. My understanding is that folks working on the next version
of the specification intend to include this kind of a mapping.

  The way to access this functionality in current implementations is to
make use of vendor extensions.

  In TopLink Essentials, you can use a DescriptorCustomizer. (described
in the table at the following link under the heading:
toplink.descriptor.customizer.<ENTITY>)

http://www.oracle.com/technology/products/ias/toplink/JPA/essentials/toplink-jpa-extensions.html#TopLinkCustomizationValidation

  In that customizer, you can add what TopLink calls a
DirectCollectionMapping. Some information about
DirectCollectionMappings can be found at the following link:

http://www.oracle.com/technology/products/ias/toplink/doc/10131/main/_html/dcmapcfg.htm#CHDGEGBJ

  Let me know if you need help getting this configured.

-Tom


Aleksei Valikov wrote:

> Hi.
>
> Is there a spec-compliant way to map simple collections?
> Like this one:
>
> public List<String> anyURI;
>
> Currently I have to simulate a collection of entities:
>
> @OneToMany(cascade = {
> CascadeType.ALL
> })
> public List<SimpleCollectionTypesType.AnyURIItem> anyURIItems;
>
>
> @Entity
> @Inheritance(strategy = InheritanceType.JOINED)
> public static class AnyURIItem
> implements Item<String> , Equals, HashCode
> {
>
> @Basic
> public String value;
> @Id
> @GeneratedValue(strategy = GenerationType.SEQUENCE)
> public Long hjid;
>
> public boolean equals(Object object) { ... }
> public void hashCode(HashCodeBuilder hashCodeBuilder) {
> hashCodeBuilder.append(this.getValue());
> }
>
> public int hashCode() { ... }
> }
>
> But this is quite awkward.
>
> Bye.
> /lexi