Alternatively you could just include a MappedSuperclass that holds the query
annotations in your persistence context. No need for a property, but you
have to make sure the MappedSuperclass is part of the PersistenceUnit (add
to classes in persistence.xml, specify via
openjpa.MetaDataFactory=jpa(Types=${mappedSuperClas.class};{other types go
here}), or make sure exclude-unlisted-classes==false).

Kind of kludgy but the real key (at least for OpenJPA) is to make sure the
MetaData of the class containing @NamedQuery is parsed.

Maybe I'm misunderstanding the use case, but the real coupling is the named
queries to persistence.xml (persistence unit) - not necessarily the
compilable unit. One may have a set of entities in a utility jar which is
then used by an EJB module. The EJB module could contain persistence.xml and
orm.xml (put your query definitions here) or the MappedSuperclass I
mentioned above. That would put the query logic closer to the app or at
least outside of the model.

The same approach could be done for JSE / Servlets / whatever.

Hope this helps,

-mike

On Fri, Jun 5, 2009 at 1:54 PM, Donald Woods <dwo...@apache.org> wrote:

>
>
> Pinaki Poddar wrote:
>
>> Hi Daryl,
>>  This is one feature, for a long time, I am interested to be included in
>> JPA
>> or at least in OpenJPA. Having your queries *only* in the major
>> compilation
>> unit is a poor idea for usability point of view and takes away much of the
>> power from tuning a query a posteriori.
>>  However, I had considered the facility slightly differently than yours.
>> The primary feature that I considered important in this aspect is to
>> dissociate my queries from the major compilation units. The compilation
>> units will only refer them by name.
>>  How about the following
>>  <property name="openjpa.NamedQueryRegistry"
>> value="path/to/file/that/contains/NamedQueries.java"/>
>>
>>  and in code
>>   Query q = em.createQuery("ANameThatAppearsInNamedQueryRegsitry");
>>
>>
> Maybe by using spring/osgi blueprint to inject the config?
> Having to supply Java classes seems limiting, if the true objective is
> dynamic config to support agile development or varying Dev/QA
> environments....
>
>
>
>
>> Daryl Stultz wrote:
>>
>>> Hello,
>>>
>>> I'm frustrated by the fact that I need to define @NamedQuery and others
>>> inside my entity classes. I would like to put what I consider "logic"
>>> where
>>> I think it's appropriate which is often not with the model. Is there a
>>> way
>>> to programmatically define Named Queries Sql Result Set Mappings, etc and
>>> register them with the persistence engine? I.e. is there any alternative
>>> to
>>> using annotations/xml for defining these things?
>>>
>>> String query = "select o...";
>>> NamedQuery nq = new NamedQuery(query);
>>> Persistence.registerNamedQuery(nq);
>>>
>>> Thanks.
>>>
>>> --
>>> Daryl Stultz
>>> _____________________________________
>>> 6 Degrees Software and Consulting, Inc.
>>> http://www.6degrees.com
>>> mailto:da...@6degrees.com
>>>
>>>
>>>
>>
>> -----
>> Pinaki Poddar                      http://ppoddar.blogspot.com/
>>
>> http://www.linkedin.com/in/pinakipoddar
>> OpenJPA PMC Member/Committer
>> JPA Expert Group Member
>>
>

Reply via email to