Java Persistence 2.0, Final Release:
[QUOTE]
3.8.15 SQL Queries
Queries may be expressed in native SQL. The result of a native
SQL query may consist of entities, scalar values, or a combination of the
two. The entities returned by a query may be of different entity types.
The SQL query facility is intended to provide support for those
cases where it is necessary to
use the native SQL of the target database in use (and/or where
the Java Persistence query language cannot be used). Native SQL queries are
not expected to be portable across databases.
When multiple entities are returned by a SQL query, the entities
must be specified and mapped to the column results of the SQL statement in a
[B]SqlResultSetMapping metadata[/B] definition.
.
.
.
The following query and SqlResultSetMapping metadata illustrates the return
of multiple entity
types and assumes default metadata and column name defaults.
Query q = em.createNativeQuery(
"SELECT o.id, o.quantity, o.item, i.id, i.name, i.description "+
"FROM Order o, Item i " +
"WHERE (o.quantity > 25) AND (o.item = i.id)",
"OrderItemResults");
@SqlResultSetMapping(name="OrderItemResults",
entities={
@EntityResult(entityClass=com.acme.Order.class),
@EntityResult(entityClass=com.acme.Item.class)
})
[/QUOTE]
So, you need to take care of the entity's relationships.
Gilberto
--
View this message in context:
http://openjpa.208410.n2.nabble.com/fetch-FetchType-EAGER-and-createNativeQuery-tp5021253p5030337.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.