You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Jim O'Rourke <ji...@clearviewcatv.net> on 2009/03/21 17:39:32 UTC
NamedNativeQuery and Eager Fetch
Not sure if this is expected behavior, or a mistake on my part, so I thought
I'd ask...
I have an entity with an eager ManyToOne relationship. Native queries run
as query.getResultList() are returning NULL for the related entity, while
query.getSingleResult() return a populated related entity. The only
workaround I've found is to iterate and em.find(entity.class,
entity.getID()), but that's having a dramatic negative impact on my query
time, and these are pretty heavily used queries in my app.
Any help would be appreciated.
I'm using OPenJPA 1.1.0 (bundled with OpenEJB 3.1)
The following properties are defined in persistance.xml:
<property name="openjpa.jdbc.EagerFetchMode" value="parallel"/>
<property name="openjpa.jdbc.SubclassFetchMode" value="join"/>
My entity looks something like:
@Entity
@NamedNativeQueries({
@NamedNativeQuery(
name=Price.NATIVE_FOR_SYMBOL_DATE,
resultClass=Price.class,
query="SELECT p.* FROM Price p WHERE p.symbol = ? " +
" AND p.pricedate <= ? " +
" ORDER BY p.pricedate DESC LIMIT 1"
)})
public class Price (
public static final String
NATIVE_FOR_SYMBOL_DATE="Price.Nativefind4SymbolDate";
@Id private Integer id;
@Temporal(DATE) private Date pricedate;
private Double amount;
@ManyToOne(optional = false, fetch = EAGER, cascade = { MERGE, REFRESH })
@JoinColumn(name="symbol")
private Symbol symbol;
)
--
View this message in context: http://n2.nabble.com/NamedNativeQuery-and-Eager-Fetch-tp2514115p2514115.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: NamedNativeQuery and Eager Fetch
Posted by Jim O'Rourke <ji...@clearviewcatv.net>.
Jim O'Rourke wrote:
>
> Not sure if this is expected behavior, or a mistake on my part, so I
> thought I'd ask...
>
>
Seems a case of operator error. In an attempt to trace what was happening,
I setup a new simple project with a subset of my queries and watered down
entities and beans. In the course of debugging my first testcase, all
'flavors' of access returned the correct referenced entities.
So I ran a clean/build/enhance on my original project and re-ran my failing
testcases, and they're passing now. Sorry...
--
View this message in context: http://n2.nabble.com/NamedNativeQuery-and-Eager-Fetch-tp2514115p2514470.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.