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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:25:03+00:00 2026-05-26T01:25:03+00:00

Can somebody show me clear, complete, 100% working way to set string-typed field as

  • 0

Can somebody show me clear, complete, 100% working way to set string-typed field as ID in grails? I’ve read the docs, then read all similar ranting on the web, but failed to create a working prototype.

Here is one of my attempts to make you believe I’m not just lazily waiting for somebody to do the job )))

    class User {
  String login
  static hasMany = [apps : Application]

  static constraints = { 
  }

  static mapping = { 
    id generator: 'assigned', name: "login"
  }

}

  • 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-26T01:25:04+00:00Added an answer on May 26, 2026 at 1:25 am

    When you use a natural id you have to use the findBy method instead of the get method as demonstrated in this test:

    def user = new User(login: "test")
    assertNotNull user.save(flush: true)
    
    user = User.findByLogin("test")
    assertNotNull user
    assertEquals "test", user.login
    

    Alternately you could use a single field composite id mapping:

    class User implements Serializable {
        String login
    
        static hasMany = [apps: Application]
    
        static constraints = {
        }
    
        static mapping = {
            id composite: ['login']
        }
    }
    

    Note that composite id domain classes are required to implement Serializable.

    The test for the composite id would be:

    def user = new User(login: "test")
    assertNotNull user.save(flush: true)
    
    user = User.get(new User(login: "test"))
    assertNotNull user
    assertEquals "test", user.login
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can somebody show me if there is a way to add a row header
Can somebody show me how to set slider (Dojo slider) on some value ?
Can somebody tell me what is the meaning of Installs: 100-500. What Google Play
Please can somebody show me a simple example of parsing some HTML using libxml.
Can somebody please show me how generate a sequence in MySQL 5.1?
I'm having trouble understanding how QT works. Can somebody show me an example, where
can somebody tell / show me how to terminate session in rails 3? In
This one is fairly complex, hopefully I can make this clear enough for somebody
Can somebody please show me how to do a Java regex that takes in
Can somebody show me a simple example about session handling with GWT RequestFactory. Maybe

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.