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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:54:34+00:00 2026-06-08T12:54:34+00:00

I have a grails application using hibernate .Under grails 1.3.7 everything works properly, but

  • 0

I have a grails application using hibernate.Under grails 1.3.7 everything works properly, but when I switch to grails 2.0.3 the following problem appears:

I can’t check for unique fields under java/src directory. If I try to add or update any record with the same unique key, batch insert error appears.

Under src/groovy I create a class to check validation:

Example: LanguageCommand.groovy

package myproject.command

import org.codehaus.groovy.grails.validation.Validateable;

@Validateable
class LanguageCommand {

    String code
    String codeDescription

    static constraints= {
        code(blank:false, maxSize:50)
        codeDescription(maxSize:200)
    }
}

and under src/java I create a class to check for unique fields

Example: LanguageConstraints.groovy

package myproject.model

    constraints = {
        code unique: true
    }

where myproject.model is the name of the package that contains hibernate classes.

Note: Validation class works fine but the unique one not. i try to add unique constraints to validation class, same error appears

Error:

Error 500: Executing action [save] of controller 
           [myproject.controller.LanguageController] 
           caused exception: Runtime error executing action
Servlet: grails
URI: /myproject/grails/language/save.dispatch
Exception Message: Batch entry 0 insert into language 
                   (language_code, code_description, version, id) 
                   values (en, English, 0, 1) was aborted. 
                   Call getNextException to see the cause.
Caused by: Batch entry 0 insert into language 
           (language_code, code_description, version, id) 
           values (en, English, 0, 1) was aborted. 
           Call getNextException to see the cause.
Class: LanguageController
At Line: [125]
Code Snippet:

Any help?

  • 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-08T12:54:36+00:00Added an answer on June 8, 2026 at 12:54 pm

    Under src/groovy you will create a LanguageCommand.groovy class:

    package myproject.command
    
    import org.codehaus.groovy.grails.validation.Validateable;
    
    @Validateable
    class LanguageCommand {
        String oldCode
        String code
        String codeDescription
    
        static constraints= {
            code(maxSize:40, blank:false, validator: { val, obj ->
                if((obj.oldCode != val) && (Language.findWhere(code:val) != null))
                    return['constraints.unique.code']
            })
            codeDescription(maxSize:200)
        }
    }
    

    and in i18n/messages.properties you must write (the message you want to display it):

    constraints.unique.code = code must be unique
    

    and in the controller in update method before check of validation you must write:

    def update = {  
        LanguageCommand languageCommand ->
        Language languageInstance = Language.get(params.id)
        if(languageInstance) {
            languageCommand.oldCode = languageInstance.code
            if (!languageCommand.validate()){
                ...
                ...
            }
            ...
            ...
        }
        ...
        ...
    }
    

    Note: oldCode is a used in update only not in create, we store in it the code before updating, because if we search language by the code without changing it it return a result, then when the code = equal old code i we didn’t search language by code.

    hope this help you

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

Sidebar

Related Questions

I have a groovy/grails application that needs to serve images It works fine on
I have some text area field in my grails application. I got the following
I have this problem having to display my jasper report on my grails application.
We have developed a Web Application using grails, groovy and oracle as database with
We have a Grails 1.3.7 Application and are using Webflow for a 2 step
I have integrated spring security plugin with my grails application, which has hibernate as
I'm using Selenium for a grails application, but in order to run that I
We have developed an application using Grails, intended to be hosted on our public
I have a grails app developed under version 1.3.7It works very well when I
I have an application developed in groovy on grails(1.1.1). I've used a hibernate enable

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.