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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:41:37+00:00 2026-06-05T14:41:37+00:00

I have some domain class Incident,Problem, Category, Impact, Urgency etc. Class Incident { Category

  • 0

I have some domain class Incident,Problem, Category, Impact, Urgency etc.

Class Incident
{
   Category category
   String subject
   Impact impact
}

Class Problem
{
     Urgency urgency
     Category category
     String title
}
Class Category
{
    String categoryName
    String description
}

now, some rows are inserted into this class. now if I am deleting category it throws error like ‘grails cannot delete or update a parent row’..
so what I have to do for deleting?

  • 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-05T14:41:40+00:00Added an answer on June 5, 2026 at 2:41 pm

    The problem is – you have reference to Category in Incident and Problem classes, so database tables for those classes will have Foreign key on category table, so you can not delete a category untill you either remove those incidents/problems or update those incidents problems and set category to null (you will have to make them as nullable in domain constraints)

    So either you do

    Problem.executeUpdate('update Problem p set category = null where category = ?', [category])
    

    Same for incidents

    Or you can model your domain classes using belongsTo and hasMany and grails will handle every thing automatically

    Some thing like

    class Problem {
        static belongsTo = [category:Category]
    }
    
    class Category {
      static hasMany = [
         problems: Problem
     ]
     static mappings = {
       problems cascade: "all-delete-orphan"
     }
    }
    

    I would prefer to manage relationships using belongsTo, hasMany, hasOne rather then just using references, it expresses the model better.

    It depends on your domain model as well, in your business can problems, incidents exist without a category ! or they must belong to some category. If your answer is first option, your dont want to cascade delete, but update those incidents/problems with null category, if your answer is second option – you needs cascade all-delete-orphan

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

Sidebar

Related Questions

I have a domain class like public class Category { [Key] public string IdCategory
Assume some domain and view objects (that have no common base class) public class
I have been spending some time on this. My problem involves bringing back domain
I have a domain class using some transient property foo. Now I want to
imagine the following problem in grails you have some kind of audit trail domain
I'm seeing some unexpected behavior in Grails' createCriteria. I have a domain class that
I am using transient properties per domain class. Some of them have more than
I have some pdf files located on a http server: Like: http://domain.com/files/file1.pdf http://domain.com/files/file1.pdf http://domain.com/files/file1.pdf
I have seen on the web some domain names having prefix of ww2 or
In a RIA Domain service I have added some utility functions. For instance we

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.