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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:58:08+00:00 2026-05-19T02:58:08+00:00

In Grails/Gorm I am storing a physical site which holds objects at defined positions

  • 0

In Grails/Gorm I am storing a physical site which holds objects at defined positions.

The domain class would simply be:

EXAMPLE A

SITE DC

  • sitename
  • positionmap (1: dog, 2: cat, 3:foo, 4:bar, … up to an average of 30 items)

… but the objects change their positions and I need to later be able to see WHICH positions were occupied by WHAT at a given time (WHEN).

Thus I added another domain class

EXAMPLE B

POSITIONS DC

  • validfrom
  • validto
  • positionmap (1: dog, 2: cat, 3:foo, 4:bar)
  • belongsTo SITE

SITE DC

  • sitename

As all the objects will have a description AND there will be loads of SITEs using the same objects in it, I added a domain class to hold each and every OBJECT. Result:

EXAMPLE C

OBJECT DC

  • name
  • description

POSITIONS DC

  • validfrom
  • validto
  • positionmap (1: reference_to_dog, 2: reference_to_cat, 3:reference_to_foo, 4:reference_to_bar)
  • belongsTo SITE

SITE DC

  • sitename

Now the Map, to me, doesn’t seem reasonable anymore.

I am thinking about removing the map, replacing it by yet another domain class:

EXAMPLE D

OBJECT DC

  • name
  • description

OBJECT-TO-POSITION DC

  • positionnumber (1, 2, 3, 4, …)
  • object (reference_to_cat, reference_to_dog, reference_to_foo, …)
  • belongsTo POSITIONS

POSITIONS DC

  • validfrom
  • validto
  • belongsTo SITE

SITE DC

  • sitename

QUESTIONS

  1. Is it generally a good/bad idea to put maps into the database?
  2. How could this be achieved easier?
  3. What’s the most performant way to do it?

EDIT: A NEW APPROCH BASED ON ROBS ANSWER

Inspired by your suggestion, Rob, I drafted this data model which grants a “front-row” role to the “SeasonPlan” (amended “ResidenceHistory”).

class Zoo {
    static hasMany = [seasons: SeasonPlan]
    String name
}

// one way of representing histories
class SeasonPlan = {
    static belongsTo = [zoo: Zoo] // a SeasonPlan belongs to a single particular Zoo
    static hasMany = [cages: Cage]
    DateTime from
    DateTime until
}

class Cage {
    static belongsTo = [seasonPlan: SeasonPlan] // a cage belongs to a single seasonplan
    Species species // a cage has a single Species
    Integer cageNumber
}

class Species {
    // static hasMany = [cages: Cage] // commented out - no reverse-lookup necessary
    String name
}

This has one drawback: For every season plan there’s a new cage – though in reality the cages stay the same! (Imagine a “Integer squareMeters” within the “Cage” to make it more obvious why this isn’t desired.)

For me applying such a thing to a data model is often hard to comprehend – how do I fit “pseudo-static” data like this into the application while retaining real-world corelation?

I hope what I mean is understandable – sorry if not.

  • 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-19T02:58:09+00:00Added an answer on May 19, 2026 at 2:58 am

    I’m still trying to understand your domain; you may be overcomplicating things a bit. Would this basic model work? If not, can you explain why? I’ll update my example if I can better understand your conditions.

    Edit – updated example given the comments below.

    class Cage {
        static belongsTo = [zoo: Zoo] // a cage belongs to a single particular Zoo
        Species species // a cage has a single Species
        String name
    }
    
    class Zoo {
        static hasMany = [cages: Cage]
        String name
    }
    
    class Species {
        static hasMany = [cages: Cage] // a species can be in many different cages
        String name
    }
    
    // one way of representing histories
    class ResidenceHistory = {
        Species species
        Cage cage
        DateTime from
        DateTime until
    }
    

    Here’s how you might use the domain, then:

    def sanDiego = new Zoo(name: 'San Diego Zoo').save()
    def aviary = new Cage(name: 'Aviary', zoo: sanDiego).save()
    def elephantCage = new Cage(name: 'Elephant Area, Cage 5', zoo: sanDiego).save()
    
    def bird = new Species(name: 'Blue-Footed Booby', cage: aviary).save()
    def elephant = new Species(name: 'Asian Elephant', cage: elephantCage).save()
    
    new ResidenceHistory(species: bird, cage: aviary, from: new DateTime(), to: new DateTime().plusDays(20)).save()
    

    To answer your listed questions specifically:

    1. It depends – usually I’d prefer using the database’s relational capabilities instead of storing maps in the database. It’s much easier to work with the raw data if they aren’t serialized Java objects.
    2. See my example above.
    3. This shouldn’t matter unless performance becomes an issue. Use the solution that makes the most sense and is the easiest to maintain, and if you find that it causes performance problems, profile your application and fix the problems individually.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Grails app has the following domain objects class ProductType { String name static
now, i try understend how works in Grails domain class and GORM. So, i
When persisting domain objects using Grails/GORM I frequently find myself wondering why a save()
According to the Grails GORM guide , subclasses of domain classes share the same
In Grails I can create domain objects to a H2 in memory dataSource in
Grails GORM does not persist abstract domain classes to the database, causing a break
The following Groovy code creates a GORM-persisted domain class called Foo when written to
I have a grails app with a domain Restaurant and a domain Person. class
I am migrating my grails project from using Hibernate XML to just GORM defined
I have a grails domain class Character class Character { String name int level

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.