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

  • Home
  • SEARCH
  • 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 580797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:30:40+00:00 2026-05-13T14:30:40+00:00

I have a domain class which has two dates in it and I want

  • 0

I have a domain class which has two dates in it and I want one of them populated with the current time when a record is created for the object, like a create timestamp…

class Contact {
    Date initiatedDate
    Date acceptedDate
}

Is it sufficient just to new a Date object on one of them and make the other nullable until such a time as I need to fill it, sort of like this…

class Contact {

    static constraints = 
    {
        acceptedDate(nullable:true)
    }

    Date initiatedDate = new Date()
    Date acceptedDate
}

I’m experimenting, but I would like to know whether this is the right way to go about it or whether there is something more Grailsy or GORMy I should do in, say, an init function or by tweaking the domain object definition to have one by default, like it does an id and version.

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-13T14:30:41+00:00Added an answer on May 13, 2026 at 2:30 pm

    What you’ve written should work but you can use the GORM auto-timestamping feature by simply adding a field:

    class Contact {
        Date dateCreated
    }
    

    If you want to keep your own names for the fields the same grails docs also show you how to use GORM events to set fields on save or update.

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my domain model I have an abstract class CommunicationChannelSpecification, which has child classes
I have a domain class containing a couple of fields. I can access them
I have a simple class which has a static constructor and a instance constructor.
So let's say we have a domain object such as the following public class
I have the following models. # app/models/domain/domain_object.rb class Domain::DomainObject < ActiveRecord::Base has_many :links_from, :class_name
I have a class in my domain model called JobPlan this class is stored
Here is the domain that I wish to have: public class Person { public
Let's say you have a domain entity User and you want to support the
I have two questions How do I achieve the following, I have a domain
I have the following two table (which are tied in with Spring security -

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.