이것은 해결하기를 희망하는 긴 질문과 이상한 문제입니다. 내 클라이언트가 내 서버에 JSON 개체를 게시합니다. 보고서를 저장하고 내 jms에서 다른 목적으로 생성 된 ID를 사용하지만 가끔 내 ID가 성공적으로 추가되면 null ID를 얻습니다. 이 문제를 어떻게 방지 할 수 있습니까? 내 컨트롤러에서 내 도메인Grails 엔티티 ID 삽입 후
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
}
에서
, 나는
내 추가 보고서 서비스에서JSONObject json = request.JSON
AddReportService svc = new AddReportService()
def id= svc.addReport(json)
json.put("id",id)
jmsService.send(queue:'msg.new', json.toString())
, 내 JMS에서
JSONObject obj = report
Reports reports = new Reports()
...
reports.save(flush:true)
myid = reports.id
return myid
을 가지고
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)