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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:08:58+00:00 2026-06-06T00:08:58+00:00

this is a long question and weird problem that I hope to solve. My

  • 0

this is a long question and weird problem that I hope to solve. My client post a JSON object to my server. I save the report and use the id generated for another purpose in my jms, but sometimes getting null id when my add was successful. How can I prevent this?

In my domain

int id
String reportImage
Date reportDateTime;
static constraints = {
    id(blank:false, unique:true) 
    reportImage (blank:true, nullable:true)
    reportDateTime (blank:false)
}
def afterInsert = {

    id= this.id

} 

In my controller, I have

JSONObject json = request.JSON        
AddReportService svc = new AddReportService()        
def id= svc.addReport(json)
json.put("id",id)
jmsService.send(queue:'msg.new', json.toString())

In my add report service,

JSONObject obj = report
Reports reports = new Reports()
       ...
reports.save(flush:true)
myid = reports.id
return myid

In my jms,

def jmsService
static transactional = false
static exposes = ['jms']


@Queue(name='msg.new')    
def createMessage(msg) {
    JSONObject json = new JSONObject(msg)
    int id = json.get("id") // sometimes is null, but report was added. How to prevent?


    AlertManagement am = new AlertManagement()
    am.IsToSendAlert(id)
  • 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-06T00:08:59+00:00Added an answer on June 6, 2026 at 12:08 am

    If the id is null after an insert, it almost certainly means the insert failed in some way. When you call reports.save(), you should either add failOnError: true to or examine the return value.

    A few comments on your code:

    • you don’t need to declare an id property in domain objects, grails adds one implicitly (of type long).
    • likewise, the id constraints are redundant.
    • assigning id = this.id in the afterInsert handler does nothing and is unnecessary. GORM makes sure the domain object id is set correctly after an insert.

    Also, how and when objects get persisted in grails isn’t always straightforward, especially if you add in manual flushing and transactions. This is a must read to get a better understanding: http://blog.springsource.com/2010/06/23/gorm-gotchas-part-1/

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

Sidebar

Related Questions

Sorry for this long post. The question is however small but requires full detail.
This is a problem am facing for long now also asked a question regarding
This is a somewhat long question, but I hope I can express it clearly.
I understand that this is a very long question, but i wanted to ask
I apologize in advance; this is a long question. I've tried to simplify as
:) This might look to be a very long question to you I understand,
Firstly, This might seem like a long question. I don't think it is... The
This question has been puzzling me for a long time now. I come from
This question is an exact duplicate of: Why generate long serialVersionUID instead of a
JD Long helped me with this: question about manual annotation . But is it

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.