Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Native queries & batch hint

Batch reading requires the usage of generated SQL, as we must generate the
batch query based on the original query.  Native SQL queries are not
supported, you should get a better error though, please log a bug for the
null-pointer.

Join fetching is supported on native SQL queries, provided you give the
correct SQL that returns the expected data.


Swierzynski, Rafal wrote:
> 
> Hi EclipseLink users and developers.
> 
> We are using native queries, and we really like the "eclipselink.batch"
> feature. However, these two don't work together. When we try to set this
> hint for a native query to batch retrieve a dependant collection, we get a
> NPE. The reason is that the descriptor field in the query is not
> initialized, and a lookup for a string token is attempted on a null
> reference. The NPE can be avoided if the following line is added in
> EntityManagerImpl.createNativeQueryInternal(String, Class):
> query.changeDescriptor(getServerSession());
> After this operation, the batch kind of works. Kind of means that it
> doesn't throw a NPE, and the second SQL is actually issued to the
> database. The bad thing is that the sql that is issued is incorrect. So,
> for example, this is the native query:
> SELECT p.* FROM Parent p WHERE p.id < 10
> Parent contains a collection of Child (unidirectional, a link table is
> used), and I set the batch hint (of course the patched EntityManagerImpl
> is needed). The second SQL is:
> SELECT c.*, p.id FROM parent p, child c, link_table l WHERE l.parent_id =
> p.id and l.child_id = c.id
> whereas it should also contain the additional where condition like this;
> and p.id < ?
> with the parameter bound to 10, reflecting the where clause from the first
> query. This is how it works for JPQL queries. Without it, the second query
> will load all Child elements that have a Parent as these are all inner
> joins. With thousands of Parents with many Child elements, this gets bad.
> 
> I would like to ask if there is any reason why hints are not supported for
> native queries, and if it is just an overlooking, is it possible to make
> the batch work like for JPQL? What would have to be done in order for this
> to work?
> 
> The tests are based on EL 2.0.0.
> 
> Attached is a zip package with a maven project with a test case and a
> patched EntityManagerImpl to prevent the NPE mentioned.
> 
> Best regards,
> RafaƂ
>  
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://old.nabble.com/Native-queries---batch-hint-tp27224057p27227221.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top