openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig L Russell <Craig.Russ...@Sun.COM>
Subject Re: JPA spec wierdism?
Date Fri, 16 Feb 2007 01:02:31 GMT
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!


Mime
View raw message