Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Convert query to native query
Convert query to native query [message #660989] Tue, 22 March 2011 15:18 Go to next message
Patrick Haun is currently offline Patrick HaunFriend
Messages: 30
Registered: October 2009
Member
Is it possible to convert a JPQL or CriteriyQuery to a native Query? The query is logged by eclipselink. Is it possible to get the query as string?
Re: Convert query to native query [message #661194 is a reply to message #660989] Wed, 23 March 2011 14:42 Go to previous message
Patrick Haun is currently offline Patrick HaunFriend
Messages: 30
Registered: October 2009
Member
I found a solution:

final Query query = entityManager.createQuery(queryString);

      if (entityManager instanceof EntityManagerImpl)
      {
         final Session session = ((EntityManagerImpl) entityManager).getActiveSession();
         if (query instanceof EJBQueryImpl)
         {
            final EJBQueryImpl<?> ejbQueryImpl = (EJBQueryImpl<?>) query;
            final DatabaseQuery databaseQuery = ejbQueryImpl.getDatabaseQuery();
            databaseQuery.prepareCall(session, new DatabaseRecord());
            String sqlString = databaseQuery.getSQLString();
         }
      }
Previous Topic:NullPointerException in CriteriaQueryImpl when using multiselect
Next Topic:EclipseLink DBWS @PostConstruct Exception
Goto Forum:
  


Current Time: Wed Nov 26 01:53:14 GMT 2014

Powered by FUDForum. Page generated in 0.01606 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software