當我試圖挽救receiveTransaction我得到這個例外的Grails 2.5.0的持久對象空ID
Caused by: org.postgresql.util.PSQLException: ERROR: null value in column "letter_id" violates not-null constraint Detail: Failing row contains (5, 0, RECEIVE, 67, nraed, 2015-06-22 12:56:17.111, null, ملوخية, 3, null, 1, f, 1, DONE, ps.police.parchive.LetterTransaction, null). at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:560) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:363) ... 9 more
信的hasMany letterTransaction
LetterTransaction域:
class LetterTransaction {
ActionEnum action
Date dateTime
Party party
ArchiveStructure archiveStructure
Boolean reviewed = Boolean.FALSE
TransactionStatus status=TransactionStatus.PENDING
String notes
Long sequence
LetterTransaction relatedTransaction
RelatedLetter relatedLetter
List signs = new ArrayList()
List reviewLogs = new ArrayList()
List divisionPathes = new ArrayList()
List targets = new ArrayList()
String createdBy
boolean deleted
static transients = ['deleted']
static belongsTo = [letter:Letter]
static hasMany = [
targets:Party,
// related letters in case this letter is related to other letters (Attachments)
// actions have bean specified by organization manager التاشيرات
signs:Sign,
// all reviewing actions have bean taken for this letter
reviewLogs:ReviewLog,
// this devision path describes where scans have bean saved, according the ArchiveStructure for this letter
divisionPathes:DivisionPath
]
}
in controller
LetterTransaction sendTransactionInstance = LetterTransaction.get(params.long("transactionId"))
LetterTransaction receiveTransaction=new LetterTransaction()
receiveTransaction.action=ActionEnum.RECEIVE
receiveTransaction.letter=Letter.get(sendTransactionInstance.letter.id)
receiveTransaction.status=TransactionStatus.DONE
receiveTransaction.relatedTransaction=sendTransactionInstance
receiveTransaction.party=InternalDepartment.findByCoreId(session.departmentId)
receiveTransaction.dateTime=new Date()
receiveTransaction.sequence=params.long("sequence")
receiveTransaction.targets=[sendTransactionInstance?.party]
receiveTransaction.notes = params.comments
receiveTransaction.archiveStructure = ArchiveStructure.get(params.long("archiveStructure.id"))
if(!receiveTransaction.hasErrors() && receiveTransaction.save(flush: true,failOnError: true)){
sendTransactionInstance.letter.addToTransactions(receiveTransaction)
sendTransactionInstance.letter.save(flush: true,failOnError: true)
//copy all scans to the new folder
manageService.copyLetterScansFromOrganization(sendTransactionInstance, sendTransactionInstance?.party?.coreId,null, getCurrentUser())
render "OK"
}else{
def errors=g.renderErrors(bean: receiveTransaction)
render errors
}
請確保'Letter.get(sendTransactionInstance.letter.id)'不是'null' – Armaiti
letterTransaction中的字母是可空的false .. LetterTransaction屬於字母,因此它不能爲空 –