You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Dain Sundstrom <da...@iq80.com> on 2007/02/16 01:57:24 UTC
JPA spec wierdism?
This is the only group of JPA developers, I know of so I'm going to
ask here...
One thing I find strange is the namespace of NamedQueries. I declare
NamedQueries using either an annotation on my entity or in xml using
a named-query element nested in my entity element. This implies to
me as a developer that the named queries are "owned" by the entity.
But when you go to use a named query you must retrieve it using the
EntityManager like this:
Query query = entityManager.createNamedQuery(name);
Which means that the queries have a single global namespace. To make
matters worse there doesn't seem to be any enforcement in the schema
to make duplicate queries illegal.
Is my understanding correct?
Also, OpenJPA seems to be ok with duplicate query names and randomly
pick which one to execute. I think we should at least print a
warning if a user has duplicate named queries, or maybe fire an
exception for duplicate names.
-dain
Re: JPA spec wierdism?
Posted by "Lance J. Andersen" <La...@Sun.COM>.
He is using a period.
So for an entity of Foo, the name query would be
@NamedQuery(name="Foo.query",
query ="select f from foo f")
Dain Sundstrom wrote:
> On Feb 15, 2007, at 5:19 PM, Lance J. Andersen wrote:
>
>>> Yes. The best we could do is to make a recommendation that users
>>> guarantee uniqueness of names by prepending the entity name to the
>>> query name.
>>>
>> This is exactly what Mike Keith recommends in his book Pro EJB 3 Java
>> Persistence API
>
> Do you know which character he uses as the separator? I'm using a
> period, but if everyone else is using say '#', I can change my code
> generator.
>
> -dain
RE: JPA spec wierdism?
Posted by Patrick Linskey <pl...@bea.com>.
I use period also in my examples:
Query q = em.createQuery("Person.findAll");
We actually came up with this convention before the spec went out.
Bummer that we didn't just fix the spec.
-Patrick
--
Patrick Linskey
BEA Systems, Inc.
_______________________________________________________________________
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.
> -----Original Message-----
> From: Dain Sundstrom [mailto:dain@iq80.com]
> Sent: Thursday, February 15, 2007 5:39 PM
> To: open-jpa-dev@incubator.apache.org
> Subject: Re: JPA spec wierdism?
>
> On Feb 15, 2007, at 5:19 PM, Lance J. Andersen wrote:
>
> >> Yes. The best we could do is to make a recommendation that users
> >> guarantee uniqueness of names by prepending the entity
> name to the
> >> query name.
> >>
> > This is exactly what Mike Keith recommends in his book Pro EJB 3
> > Java Persistence API
>
> Do you know which character he uses as the separator? I'm using a
> period, but if everyone else is using say '#', I can change my code
> generator.
>
> -dain
>
Re: JPA spec wierdism?
Posted by Dain Sundstrom <da...@iq80.com>.
On Feb 15, 2007, at 5:19 PM, Lance J. Andersen wrote:
>> Yes. The best we could do is to make a recommendation that users
>> guarantee uniqueness of names by prepending the entity name to the
>> query name.
>>
> This is exactly what Mike Keith recommends in his book Pro EJB 3
> Java Persistence API
Do you know which character he uses as the separator? I'm using a
period, but if everyone else is using say '#', I can change my code
generator.
-dain
Re: JPA spec wierdism?
Posted by "Lance J. Andersen" <La...@Sun.COM>.
>
> Yes. The best we could do is to make a recommendation that users
> guarantee uniqueness of names by prepending the entity name to the
> query name.
>
This is exactly what Mike Keith recommends in his book Pro EJB 3 Java
Persistence API
Re: JPA spec wierdism?
Posted by Dain Sundstrom <da...@iq80.com>.
On Feb 15, 2007, at 5:02 PM, Craig L Russell wrote:
> Hi Dain,
>
> On Feb 15, 2007, at 4:57 PM, Dain Sundstrom wrote:
>
>> This is the only group of JPA developers, I know of so I'm going
>> to ask here...
>
> This was discussed at length in the expert group and the result is
> in the specification.
That's too bad. It was a very surprising discovery for me.
>> One thing I find strange is the namespace of NamedQueries. I
>> declare NamedQueries using either an annotation on my entity or in
>> xml using a named-query element nested in my entity element. This
>> implies to me as a developer that the named queries are "owned" by
>> the entity.
>
> And yet, they are not. The namespace for queries is the entire
> PersistenceUnit.
>
>> But when you go to use a named query you must retrieve it using
>> the EntityManager like this:
>>
>> Query query = entityManager.createNamedQuery(name);
>>
>> Which means that the queries have a single global namespace. To
>> make matters worse there doesn't seem to be any enforcement in the
>> schema to make duplicate queries illegal.
>
> This allows implementations to add value. ;-)
LOL
>> Is my understanding correct?
>
> Yes. The best we could do is to make a recommendation that users
> guarantee uniqueness of names by prepending the entity name to the
> query name. As a side benefit, it's then possible to actually find
> the query to debug it.
That is how, I'm declaring my queries now :(
>> Also, OpenJPA seems to be ok with duplicate query names and
>> randomly pick which one to execute. I think we should at least
>> print a warning if a user has duplicate named queries, or maybe
>> fire an exception for duplicate names.
>
> Sounds like added value to me. Care to file a JIRA with your
> observations and a request for your preferred implementation?
Done. OPENJPA-152
-dain
Re: JPA spec wierdism?
Posted by Craig L Russell <Cr...@Sun.COM>.
Hi Dain,
On Feb 15, 2007, at 4:57 PM, Dain Sundstrom wrote:
> This is the only group of JPA developers, I know of so I'm going to
> ask here...
This was discussed at length in the expert group and the result is in
the specification.
>
> One thing I find strange is the namespace of NamedQueries. I
> declare NamedQueries using either an annotation on my entity or in
> xml using a named-query element nested in my entity element. This
> implies to me as a developer that the named queries are "owned" by
> the entity.
And yet, they are not. The namespace for queries is the entire
PersistenceUnit.
> But when you go to use a named query you must retrieve it using the
> EntityManager like this:
>
> Query query = entityManager.createNamedQuery(name);
>
> Which means that the queries have a single global namespace. To
> make matters worse there doesn't seem to be any enforcement in the
> schema to make duplicate queries illegal.
This allows implementations to add value. ;-)
>
> Is my understanding correct?
Yes. The best we could do is to make a recommendation that users
guarantee uniqueness of names by prepending the entity name to the
query name. As a side benefit, it's then possible to actually find
the query to debug it.
>
> Also, OpenJPA seems to be ok with duplicate query names and
> randomly pick which one to execute. I think we should at least
> print a warning if a user has duplicate named queries, or maybe
> fire an exception for duplicate names.
Sounds like added value to me. Care to file a JIRA with your
observations and a request for your preferred implementation?
Craig
>
> -dain
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!