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 9084395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:59:17+00:00 2026-06-16T20:59:17+00:00

I have a very simple Groovy class where I’m just trying to select a

  • 0

I have a very simple Groovy class where I’m just trying to select a String from an Oracle 11g database using a native SQL query through Hibernate 3.3.2 GA. It seems so simple and yet I can’t make sense of the results I’m getting. Here is the code:

package serialize

import org.hibernate.cfg.Configuration
import org.hibernate.transform.ToListResultTransformer

class SerializeDatabaseObjects {


    static main(args) {

        def sessionFactory = initHibernate()

        def session = sessionFactory.openSession()

        def tx
        def result

        try {
            tx = session.beginTransaction()

             result = session
                .createSQLQuery("""Select 'Hello World!' from dual""")
                .setResultTransformer(ToListResultTransformer.INSTANCE) 
                .list()

            tx.commit()
        }
        catch (Exception e) {
            if (tx!=null){ 
                tx.rollback() 
            }
            throw e
        }
        finally {
            session.close()
        }


        println result

        sessionFactory.close()
    }

    static initHibernate(){
        return new Configuration().configure().setProperty("hibernate.show_sql", "true").buildSessionFactory()
    }
}

Output:

Hibernate: Select 'Hello World!' from dual
[[H]]

The ToListResultTransformer was my latest attempt to get the entire 'Hello World!' String to get printed but IMO shouldn’t be needed. But no matter what I try ‘H’ is always the result.

How do I get the entire ‘Hello World’ string to be returned?

  • 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-16T20:59:18+00:00Added an answer on June 16, 2026 at 8:59 pm

    As I was typing this question I figured out the answer. It appears that Hibernate is interpreting the result as a character instead of a String and therefore only returning ‘H’.

    The way I found to fix this is to add a column alias in the select statement and then use addScalar(String columnAlias, Type type) to specify that the result should be interpreted as a String.

    Again, I used a ResultTransformer(AliasToEntityMapResultTransformer) so my result would contain the column name and it’s contents but it is not strictly necessary.

    If anyone would like to expand on why Hibernate is mapping the result as a character instead of a String or suggest an alternative(easier) way of forcing the result to be a string, please comment or post an answer.

    Here is the code that produces the expected results:

    package serialize
    
    import org.hibernate.cfg.Configuration
    import org.hibernate.transform.AliasToEntityMapResultTransformer
    import org.hibernate.type.StringType
    
    class SerializeDatabaseObjects {
    
    
        static main(args) {
    
            def sessionFactory = initHibernate()
    
            def session = sessionFactory.openSession()
    
            def tx
            def result
    
            try {
                tx = session.beginTransaction()
    
                 result = session
                    .createSQLQuery("""Select 'Hello World!' as hello from dual""")
                    .addScalar("hello", new StringType())
                    .setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE)
                    .list()
    
                tx.commit()
            }
            catch (Exception e) {
                if (tx!=null){ 
                    tx.rollback() 
                }
                throw e
            }
            finally {
                session.close()
            }
    
    
            println result
    
            sessionFactory.close()
        }
    
        static initHibernate(){
            return new Configuration().configure().setProperty("hibernate.show_sql", "true").buildSessionFactory()
        }
    }
    

    And the output:

    Hibernate: Select 'Hello World!' as hello from dual
    [[hello:Hello World!]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple task I am trying to do in Groovy but
I have very simple XML in a string that I'm trying to load via
I have written a very complex database migration script in Groovy, that runs just
I have very simple web page example read from html file using python. the
I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have a very simple Mapping I'm trying to do. I'm following the NHibernate
I am new to SoapUI and have just configured a very simple MockService. Is
I have very simple code: List<String> list = new ArrayList<String>(); String a = a;
I have very simple application just in the body of Main method. I have
I have very simple form along with two database tables. In this form is

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.