You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by cgray <cg...@gmail.com> on 2010/02/06 01:29:04 UTC

How to Setup a Named Query to Use Eager Fetch

Hello, 

I'm seeing an oddity.  When I execute the below namequery
(Country.findCountry) the first time one sql statement is created that
fetches all Country objects from the database.  The second time this named
query gets executed it creates a sql query per row in the database (over 200
rows).  It seems like its lazy loading the second time, any ideas on how to
fetch this eagerly or any other ideas to limit the second hit to one query? 
This is using the hibernate driver. 


@Entity
@Table(name = "COUNTRY")
@NamedQueries({@NamedQuery(name = "Country.findCountry", query = "SELECT c
FROM Country c")})
public class Country implements Serializable {

   
    @Column(name = "COUNTRY_CODE")
    @Id
    private String countryCode;
    
-- 
View this message in context: http://n2.nabble.com/How-to-Setup-a-Named-Query-to-Use-Eager-Fetch-tp4523309p4523309.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: How to Setup a Named Query to Use Eager Fetch

Posted by Craig L Russell <Cr...@Sun.COM>.
Hi,

If you're "using the Hibernate driver" then this is probably the wrong  
list to ask. This list is for questions about the OpenJPA  
implementation of JPA...

Craig

On Feb 5, 2010, at 4:29 PM, cgray wrote:

>
> Hello,
>
> I'm seeing an oddity.  When I execute the below namequery
> (Country.findCountry) the first time one sql statement is created that
> fetches all Country objects from the database.  The second time this  
> named
> query gets executed it creates a sql query per row in the database  
> (over 200
> rows).  It seems like its lazy loading the second time, any ideas on  
> how to
> fetch this eagerly or any other ideas to limit the second hit to one  
> query?
> This is using the hibernate driver.
>
>
> @Entity
> @Table(name = "COUNTRY")
> @NamedQueries({@NamedQuery(name = "Country.findCountry", query =  
> "SELECT c
> FROM Country c")})
> public class Country implements Serializable {
>
>
>    @Column(name = "COUNTRY_CODE")
>    @Id
>    private String countryCode;
>
> -- 
> View this message in context: http://n2.nabble.com/How-to-Setup-a-Named-Query-to-Use-Eager-Fetch-tp4523309p4523309.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.

Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!