openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Linskey" <plins...@bea.com>
Subject RE: Collection (or Map) relationships and null
Date Mon, 11 Dec 2006 22:44:58 GMT
> -----Original Message-----
> From: Dain Sundstrom [mailto:dain@iq80.com] 
> Sent: Monday, December 11, 2006 2:23 PM
> To: open-jpa-dev@incubator.apache.org
> Subject: Re: Collection (or Map) relationships and null
> 
> On Dec 11, 2006, at 2:09 PM, Patrick Linskey wrote:
> 
> > If you have a null indicator for the collection / map field, then
> > OpenJPA will preserve the null-ness.
> 
> What's that?  I see you can specify a column as being not nullable  
> but I don't see anything in the spec about null and collections.

Looking at things, I'm not 100% how to configure via JPA. It could be
via the org.apache.openjpa.persistence.jdbc.EmbeddedMapping annotation
(note the nullIndicator property there) -- in Kodo parlance, collections
and maps themselves are 'embedded', and it's their values that are
typically not embedded. But our docs certainly don't make that clear
currently.

> > Otherwise, the default value will be dictated by what your no-args
> > constructor does (or, equivalently, what your member field
> > initializations do).
> 
> What about for a bean acquired via load?  Will JPA set an empty  
> collection into the field, or do I need to add initialize the field?

We'll call the no-args constructor in the object to create the new
record, and then populate things from the DB. If you don't have a
no-args constructor, we create one for you during enhancement. When we
auto-gen one, I don't remember whether we attempt to emulate
initialization that you do elsewhere.

> Actually, maybe just skip all that :)  What is the best practice for  
> Collection and Map fields?

If you want to distinguish between null and not-null, use indicators.
Otherwise, initialize them to non-null values.

> Also what about this question:
> 
> >> Also, what happens when someone puts a bad value on the Collection
> >> (or Map).  For example, a null in the collection, or an 
> entry in the
> >> map where the pk doesn't match the bean added.

No idea. If you've got database constraints in place, you'll at least
get an exception at commit time.

-Patrick
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

Mime
View raw message