this solution seems to be outdated now.
since i have updated glassfish to the latest official release by sun (Sun Java System Application Server 9.1_02 (build b04-fcs)) the code provided by gyorke does not work anymore.
I get the following exception:
"java.lang.ClassCastException: com.sun.enterprise.util.QueryWrapper cannot be cast to oracle.toplink.essentials.ejb.cmp3.EJBQuery"
how do I have write the code now to take a look at the native sql queries?
One option is to get hold of Toplink em. That is as follows
EntityManager toplinkEm = em.getDelegate();
dbQuery.prepareCall(((EntityManagerImpl)em.getDelegate ()).getServerSession(), new DatabaseRecord());
that made the trick. thanks.
> DatabaseQuery dbQuery =
> ()).getServerSession(), new DatabaseRecord());
This works fine when using em.createNamedQuery(), but gives a IllegalArgumentException when using em.createQuery(). Is there any way to get the database query for an arbitrary JPQL string within your code?
TopLink generates the SQL dynamically during runtime. Although TopLink can cache the statements they are not really 'stored' anywhere. The easiest way to view the SQL is to turn on logging using the "toplink.logging.level" "finer" persistence unit properties. To get the SQL within your application you can call.
DatabaseQuery dbQuery = ((oracle.toplink.essentials.ejb.cmp3.EJBQuery)em.createNamedQuery("name")).getDatabaseQuery();
dbQuery.prepareCall(((EntityManagerImpl)em.getDelegate()).getServerSession(), new DatabaseRecord());
thanks, it works.
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Participation.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.