Hi Daryl,
Actually, there is an way you can externalize your queries from your Java
code.
orm.xml has a 'global' named-query clause.
1. put you JPQL query string there.
2. If you do not want to write your POJO entities in orm.xml, that is OK.
3. specify orm.xml in <mapping-file> clause in persistence.xml
So effectively we got 3 things:
1. Employee.java
@Entity // this is required if you did not include it in orm.xml
public class Employee {...}
2. a orm.xml only with your queries
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings>
<named-query name="Employee.findAll">
<query>SELECT x FROM Employee x</query>
</named-query>
</entity-mappings>
3. persistence.xml that has both orm.xml and <class>
<persistence-unit name="named-query">
<mapping-file>orm.xml</mapping-file>
<class>access.Employee</class>
</persistence-unit>
Now your code can refer to em.createNamedQuery("Employee.findAll");
and you can tune this queries post-compilation by merely editing orm.xml.
PS: > Naturally, since you're a JPA expert and I'm just a lowly beginner...
In this game, anybody is as good as the other. That self-serving 'expert'
designation is ego-massaging -- pure and simple.
Daryl Stultz wrote:
>
> On Fri, Jun 5, 2009 at 11:33 AM, Pinaki Poddar <[email protected]> wrote:
>
>>
>>
>> However, I had considered the facility slightly differently than yours.
>
>
> Naturally, since you're a JPA expert and I'm just a lowly beginner... I
> was
> just putting out a "sketch" to help folks understand what I was after.
>
>>
>> The primary feature that I considered important in this aspect is to
>> dissociate my queries from the major compilation units.
>
>
> By "major compilation units" do you mean "classes mostly of Java (and not
> embedded SQL/JPQL)"?
>
>>
>> How about the following
>> <property name="openjpa.NamedQueryRegistry"
>> value="path/to/file/that/contains/NamedQueries.java"/>
>>
>> and in code
>> Query q = em.createQuery("ANameThatAppearsInNamedQueryRegsitry");
>>
>> Not bad, so far. I imagine NamedQueries.java would implement some
>> interface
> that expects a return of a collection of NamedQueries or something?
>
> --
> Daryl Stultz
> _____________________________________
> 6 Degrees Software and Consulting, Inc.
> http://www.6degrees.com
> mailto:[email protected]
>
>
-----
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-tp3030386p3033053.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.