facebook

Ad-hoc SQL – how to run

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #312591 Reply

    Greg Soulsby
    Member

    I am finding the classes autogenerated from my database very productive to work with.

    However, I have a need to pull data joined from many tables. The exact requirement has to be defined at run time. SQL it has to be.

    Once I have built the ad-hoc sql, how do I run it? Although it is not an update, should the POJO be wired as a DOA?

    Thanks

    Greg

    #312595 Reply

    davemeurer
    Member

    Hi Greg,

    There are a couple options that come to mind depending on what you can do with your query.

    A. If you can form it into a JPQL statement, you can use the JPADao helper class that is generated with scaffolding to run the executeQuery method. The JPADao helper class is represented in any DAO created. So, you’ll see that DAO is already wired in the Service class, for example. It’s usually in the form <domain object>DAO. This helper class simply taps into the EntityManager, http://download.oracle.com/javaee/6/api/javax/persistence/EntityManager.html, which you can obviously use as well and is wired into the Scaffolded DAO, which leads me to the second option….

    B. If the query has to be in native SQL, I would recommend creating a method in the DAO itself to accept the SQL text and call the EntityManager. I believe the method you want to take a look at is createNativeQuery.

    HTH,
    Dave

    #312747 Reply

    Greg Soulsby
    Member

    This message has not been recovered.

    #312763 Reply

    davemeurer
    Member

    This message has not been recovered.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Ad-hoc SQL – how to run

You must be logged in to post in the forum log in