openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <michael.d.d...@gmail.com>
Subject Re: Code organization
Date Mon, 08 Jun 2009 18:06:59 GMT

Hi David,

Actually this is working today - I wrote a simple testcase to verify it on
trunk. Should work on 1.2.x as well. 

-mike 

David Beer-2 wrote:
> 
> Hi Mike
> 
> 
> This sort of method would certainly fit my needs and method of working
> more. Is there a JIRA item for this so that I can add a comment?
> 
> On Fri, 5 Jun 2009 16:50:59 -0500 Michael Dick
> <michael.d.dick@gmail.com> wrote:
> 
>> On Fri, Jun 5, 2009 at 3:25 PM, David Beer
>> <david.m.beer@googlemail.com>wrote:
>> 
>> > Hi All
>> >
>> > I too would much rather see @NamedQuery(ies) defined in a seperate
>> > class like I do other more complicated queries. I also see this as a
>> > good way of keeping things modular or decoupled from the model.
>> >
>> > Using a seperate java class which then registers those queries at
>> > run time would be a good way of doing things. The registration not
>> > need be in the persistence.xml file as long as it can be added to
>> > the persistence unit later.
>> 
>> 
>> This can be done, provided the separate class is an Entity /
>> MappedSuperclass. You have to add it to the PersistenceUnit at factory
>> creation time though.
>> 
>> Something like this should work..
>> 
>> Map m = new HashMap()
>> m.put("openjpa.MetaDataFactory=jpa(Types=${list all your entity types
>> here};${new query container type goes here})");
>> 
>> emf =
>> javax.persistence.Persistence.createEntityManagerFactory(emfName, m);
>> 
>> The catch is that if Types is specified it must be the complete list
>> (as I remember).
>> 
>> hth
>> -mike
>>
>>
>> 
>> >
>> > David
>> >
>> > On Fri, 5 Jun 2009 08:33:19 -0700 (PDT)
>> > Pinaki Poddar <ppoddar@apache.org> 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");
>> > >
>> > >
>> > > 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:daryl@6degrees.com
>> > > >
>> > > >
>> > >
>> > >
>> > > -----
>> > > Pinaki Poddar                      http://ppoddar.blogspot.com/
>> > >
>> > > http://www.linkedin.com/in/pinakipoddar
>> > > OpenJPA PMC Member/Committer
>> > > JPA Expert Group Member
>> >
>> >
> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/Code-organization-tp3030386p3044586.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message