openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Sutter" <kwsut...@gmail.com>
Subject Re: what to expect - jpa spec or impl discretion
Date Mon, 21 Jul 2008 17:01:21 GMT
Nathan,
Comments embedded below.  This is just my interpretation of the spec (I am a
member of the JPA expert group, but I am not the lead).  Posting to the
EclipseLink forum might be interesting as well...

On Mon, Jul 21, 2008 at 10:15 AM, Beyer,Nathan <NBEYER@cerner.com> wrote:

> I'm trying to write a bit of code that's portable between JPA providers and
> ran into a few differences and I'd like to know if they are undefined bits
> of the spec or just me doing something silly.
>
> 1.      0 is considered null for primary key fields (@Id) of type int, long
> - OpenJPA DOES NOT do this, but other providers, such as EclipseLink do. Is
> this in the spec or up for debate?


The spec does not identify valid values for a given annotation or field
type.  But, logic would say that 0 is a valid int or long and, thus, should
be allowed as a primary key value.  Of course, you could say that this
wouldn't be a very solid value for a primary key, but it should be allowed
in my book.


>
> 2.      Return value of native queries is an Object[] or a List - Consider
> the following snippets
>
>                 // LOG is table name with a 'sequence' column/field of Java
> type 'long'
>        final Query query = entityManager.createNativeQuery("SELECT
> MIN(e.sequence), MAX(e.sequence) FROM LOG e");
>        final Object result = query.getSingleResult();
>
>                With OpenJPA a Object[] is returned, in EclipseLink a List
> is returned. Is this defined anywhere? How can I define it.


I'm a little confused by your example.  You indicate that OpenJPA is
returning an array of Objects?  Did you mean that OpenJPA is returning a
single Object?  The JavaDoc for getSingleResult is like this:

/**
* Execute a SELECT query that returns a single result.
* @return the result
* @throws NoResultException if there is no result
* @throws NonUniqueResultException if more than one result
* @throws IllegalStateException if called for a Java
* Persistence query language UPDATE or DELETE statement
*/
public Object getSingleResult();

So, I could see where someone might return a List (since it's an Object),
but returning an array of Objects seems like a stretch.

Given that, I would expect the result to be a single Object (not a List).
If I wanted to process a List, then I would call getResultList.  The example
usage in the spec also supports this interpretation.

Good luck with your comparisons,
Kevin


>
>
> Thanks,
> -Nathan
>
> ----------------------------------------------------------------------
> CONFIDENTIALITY NOTICE This message and any included attachments are from
> Cerner Corporation and are intended only for the addressee. The information
> contained in this message is confidential and may constitute inside or
> non-public information under international, federal, or state securities
> laws. Unauthorized forwarding, printing, copying, distribution, or use of
> such information is strictly prohibited and may be unlawful. If you are not
> the addressee, please promptly delete this message and notify the sender of
> the delivery error by e-mail or you may call Cerner's corporate offices in
> Kansas City, Missouri, U.S.A at (+1) (816)221-1024.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message