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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:53:47+00:00 2026-06-11T23:53:47+00:00

I am trying to create 2 domain classes User and MailBox There will be

  • 0

I am trying to create 2 domain classes User and MailBox

There will be 2 Mailbox for each User, one is sent, another is inbox.

I’ve tried multiple ways of solving this:

1 – (fails with a mapping exception)

Mailbox {
}

User {
    static hasOne=[inbox:Mailbox, sent:Mailbox]
}

2 – (perfectly fine until i tries to use it, then the value of sent becomes null at all times)

Mailbox {
    static belongsTo = [user: User]
}

User {     
    Mailbox inbox
    Mailbox sent
}

3 – (when I tried to create a new User by: new User(inbox: new Mailbox(), sent: new Mailbox()).save() it fails)

Mailbox {
    static belongsTo = [user: User]
}

User {
    static mappedBy = [inbox: 'id', sent: 'id']
    Mailbox inbox
    Mailbox sent   
}

What is the proper way of creating this relationship?

  • 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-11T23:53:48+00:00Added an answer on June 11, 2026 at 11:53 pm

    How about having a base class for the mailboxes? The base class can have all the mail box properties. The child classes can be empty for now and can be filled in if you discover the need for inbox or sent box specific properties as you develop your application further.

    This should work.

    class InboxMailBox extends MailBox {
        static belongsTo = [user: User]
    }
    
    class SentMailBox extends MailBox {
        static belongsTo = [user: User]
    }
    
    class User {
        InboxMailBox inbox
        SentMailBox sent
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn how to create simple groovy classes, which are not domain
I am trying to create a validation that checks to make sure a domain/url
Im trying to create a web service which gets to a URL e.g. www.domain.co.uk/prices.csv
What I'm trying to do is create a domain model with a Plain Old
I am trying to create a query in my domain service (VS 2010 Silverlight
I am trying to create a rewrite rule that accomplishes two things: Redirect (www.)?domain.com
Im trying to create ajax calls based on wordpress permalinks. Ex. domain.com/#!/tag/lorem-ipsum/ Using this
I have several domain classes that are related and I am trying to figure
I am trying to create a RewriteRule in htaccess for the domain root without
I'm trying to dynamically create domain objects in Grails and encountered the problem that

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.