persistence@glassfish.java.net

Re: Simple collections

From: Craig L Russell <Craig.Russell_at_Sun.COM>
Date: Wed, 30 May 2007 20:35:33 -0700

Hi Aleksei,

On May 29, 2007, at 11:31 PM, Aleksei Valikov wrote:

> Hi.
>
> Is there a spec-compliant way to map simple collections?
> Like this one:
>
> public List<String> anyURI;

You can map this to a BLOB if you're not looking to query the
strings. What the provider will do is serialize the contents of the
list and store it as a binary large object. When it comes back in,
the blob is deserialized into the list.

Is this more convenient for you than the alternative you outline
below? Or do you want to map this to a table in the database with a
number of rows each of which has a string value and a reference back
to the "owning" entity? It is the latter mapping that is being looked
at for future releases of the specification.

Craig
>
> 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

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell_at_sun.com
P.S. A good JDO? O, Gasp!