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

  • SEARCH
  • Home
  • 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 8161165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:26:24+00:00 2026-06-06T18:26:24+00:00

How can I access Hibernate properties from a Grails Service? In this instance I

  • 0

How can I access Hibernate properties from a Grails Service?

In this instance I have to use createSQLQuery for a legacy database and need access to the hibernate.default_schema property in order to build a valid SQL statement.

class MyService {
    def sessionFactory

    def getRows() {
        def session = sessionFactory.currentSession
        session.createSQLQuery("SELECT * FROM schema.table").list()
    }
}

UPDATE

There is a quirk with Grails 2.x multiple datasources and the setting of Hibernate properties. Properties set in additional datasources are applied to the default datasource.

The properties must be set in the hibernate object instead of the datasource object:

datasource_ds2 {
    . . .
}
hibernate_ds2 {
    default_schema = "schema"
}

They can then be accessed from the hibernate config in grailsApplication:

def grailsApplication
assert grailsApplication.config.hibernate_ds2.default_schema == "schema"
  • 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. Editorial Team
    Editorial Team
    2026-06-06T18:26:26+00:00Added an answer on June 6, 2026 at 6:26 pm

    They’re stored in the Config object, e.g.:

    class MyService {
    
        def grailsApplication
        def sessionFactory
    
        def getRows() {
    
            def defaultSchema = grailsApplication.config.hibernate.default_schema
            def session = sessionFactory.currentSession
            session.createSQLQuery("SELECT * FROM ${defaultSchema}.table").list()
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can hibernate can access a private field/method of a java class , for
Why I can access Session object in Page_Load method in instance of System.Web.UI.Page, but
I have a Java (6) application which uses Hibernate (V3.3.2) to read data from
I bump into this from time to time during class design... when I have
We are using Weblogoic9.2.3 & DB is Oracle10.2.0.3. How can we access Hibernate SessionFactory
How can I access the Hibernate mapping of my model to find out the
In my web app,I am using hibernate and hsqldb for database operations..and use Ant
how can i access Hibernate group by results. I try to get counts of
I have a struts application that uses Hibernate to access a MYSQL DB. I
I have multiple tables in a MySQL database. Lets say they look like this:

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.