Saurabh Gaur
Saurabh Gaur

Reputation: 23805

GORM - fetch results in List of Map form using HQL

I have a domain name TestCase. I'm fetching the data using HQL as below :-

def query = """
          select 
          tc.testCaseObjective as tco,
          tc.testCaseStatus as tcs
          from TestCase tc

        """

println TestCase.executeQuery(query, [max: 2])

It gives me output as :-

[["Test Case 01", "Pass"], ["work order", "Pass"]]

which is in List of List form.

But actually I want List of Map form as :-

[[tco:"Test Case 01", tcs:"Pass"], [tco:"work order", tcs:"Pass"]]

Can anyone suggest me how to achieve this? I don't want to convert it explicitly.

Upvotes: 3

Views: 1010

Answers (1)

Saurabh Gaur
Saurabh Gaur

Reputation: 23805

Got the solution using the select new map syntax in HQL to fetch the results in List of Map as below :-

def query = """
          select 
          new map(tc.testCaseObjective as tco,
          tc.testCaseSummary as tcs)
          from TestCase tc

        """

println TestCase.executeQuery(query, [max: 2])

Output :-

[[tco:"Test Case 01", tcs:"Pass"], [tco:"work order", tcs:"Pass"]]

Upvotes: 3

Related Questions