Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 107097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:42:02+00:00 2026-05-11T01:42:02+00:00

Does anybody know what is the best approach to accessing a sql view through

  • 0

Does anybody know what is the best approach to accessing a sql view through Grails (or if this is even possible)? It seems an obvious way of doing this would be to use executeQuery against the view to select a collection of rows from the view which we would not treat as a list of domain objects. However, even in this case it is not obvious which domain class to run executeQuery against, since really we are just using that domain class in order to run the query against a completely unrelated entity (the view).

Would it be preferred to create a domain class representing the view and we could then just use list() against that domain class? It seems like there would be problems with this as Grails probably expects to be able to insert, update, delete, and modify the table schema of any domain class.

[Edit:
Follow up question here: Grails Domain Class without ID field or with partially NULL composite field

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:42:02+00:00Added an answer on May 11, 2026 at 1:42 am

    You can use plain SQL in Grails which is in the case of accessing a view the preferable way (IMO):

    For example in your controller:

    import groovy.sql.Sql  class MyFancySqlController {      def dataSource // the Spring-Bean 'dataSource' is auto-injected      def list = {         def db = new Sql(dataSource) // Create a new instance of groovy.sql.Sql with the DB of the Grails app          def result = db.rows('SELECT foo, bar FROM my_view') // Perform the query          [ result: result ] // return the results as model     }  } 

    and the view part:

    <g:each in='${result}'>     <tr>         <td>${it.foo}</td>         <td>${it.bar}</td>     </tr> </g:each> 

    I hope the source is self-explanatory. The Documentation can be found here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Fields and properties have many differences other than semantic. Properties… May 11, 2026 at 11:09 am
  • added an answer First of all you should note that the load() function,… May 11, 2026 at 11:09 am
  • added an answer I considered the same sort of thing a while ago,… May 11, 2026 at 11:09 am

Related Questions

Does anybody know what is the best approach to accessing a sql view through
Does anybody know if there is a way to understand what users are doing
Does anybody know what hypothetical indexes are used for in sql server 2000? I
Does anybody know what's going on here: I run hibernate 3.2.6 against a PostgreSQL
Does anybody know what the theme parts WP_FRAMELEFT , WP_SMALLFRAMERIGHT etc are used for?
Does anybody know of a tool that allow me to inspect what files an
Does anybody know any good resources for learning how to program CIL with in-depth
Does anybody know a technique to discover memory leaks caused by smart pointers? I
Does anybody know of any sample databases I could download, preferably in CSV or
Does anybody know of a way to list up the loaded plugins in Vim

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.