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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:16:47+00:00 2026-05-23T12:16:47+00:00

I am migrating my grails project from using Hibernate XML to just GORM defined

  • 0

I am migrating my grails project from using Hibernate XML to just GORM defined in the domain classes. In one prior XML file there is a map defined:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="myproj" default-lazy="true">

    <class name="Season" table="seasons">
        <cache usage="read-only"/>
        <comment>Season</comment>
        <id name="id" type="long">
            <generator class="assigned">
            </generator>
        </id>

        <property name="seasonKey" column="season_key"/>
        <many-to-one name="league" class="Affiliation" column="league_id"/>
        <many-to-one name="publisher" class="Publisher"/>

        // MAP STARTS HERE
        <map name="seasonWeeks">
            <cache usage="read-write"/>          
            <key column="season_id"></key>
            <map-key column="week" type="int"/>
            <one-to-many class="SeasonWeek"/>
        </map>

    </class>

</hibernate-mapping>

As you can see, it creates a map of Integer, SeasonWeek. This code was previously working.

When I try to recreate the Map in GORM, it doesn’t work. The Grails 1.3.7 (the version I am on) documentation states:

The static hasMany property defines
the type of the elements within the
Map. The keys for the map must be
strings.

In my case I don’t want the map to be a string. Questions:

  • Is there any way I can do what I want here? Maybe through using the static mapping var?
  • If not, must I reinstate the old Hibernate XML file? Can I do this for just one domain class in my project and not have XML files for the rest?

Thanks.

  • 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-05-23T12:16:48+00:00Added an answer on May 23, 2026 at 12:16 pm

    I’ve found that trying to get some things to work in grails from legacy apps using GORM just isn’t the easiest thing to do. You can find a solution that fits 99% of your problems but you’ll spend a bunch more time trying to find an easy button for the last 1% of issues (like yours). I think you could accomplish this by using a transient field as the key some like (note there are two solutions, i recommend the second)…

    class Season {
    
        static mapping = {
            seasonWeeks mapKey: 'weekOfYearAsString' 
        }
    
        static hasMany = [seasonWeeks:SeasonWeek]
    
        Map seasonWeeks = [:]
    }
    
    
     class SeasonWeek{
    
            ...
    
            String name
            Integer weekOfYearAsInt
            String weekOfYearAsString
    
            String getWeekOfYearAsString(){
                return String.valueOf(weekOfYearAsInt);
            }
    
            void setWeekOfYearAsString(def value){
                this.weekOfYearAsInt = Integer.parseInt(value);
            }
        }
    

    ALSO You could avoid GORM completely (what i would do) and just handle building a map on your Season class…

    class Season{
    
       ...
    
        public Map getSeasonWeeksMap(){
            Map map = [:]
            def seasons = SeasonWeek.findBySeason(this.id)
    
            season.each(){season ->
                map.put(season.id, season)
    
            }
    
            return map
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working with a project which is using grails / hibernate with
After migrating magento from one to another hosting with different domain, I'm getting one
Migrating a project from ASP.NET 1.1 to ASP.NET 2.0 and I keep hitting this
Background: Migrating an application from ball of mud to MVC. Many classes contain HTML
We are migrating our test report data (unit, regression, integration, etc..) from an XML
Migrating from Subversion to Git using svn2git (which internally uses git-svn) I'd like to
I'm just migrating my projects from Visual Studio to Eclipse, so I can build
Just migrating from PHP 5.2 to 5.3, lot of hard work! Is the following
I have a Grails application that I am migrating from 1.0.3 to 1.3.7 It
We are migrating WI & VC from TFS 2008 to TFS 2010. One of

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.