openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim O'Rourke <jimorou...@clearviewcatv.net>
Subject NamedNativeQuery and Eager Fetch
Date Sat, 21 Mar 2009 16:39:32 GMT

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.


Mime
View raw message