我無法將任何數據插入到我的DbUser.groovy域類中。當Iam調用下面的方法時。在Grails中沒有默認值異常
\t def insertDbuserDetails(Map Hmap){
\t \t try{
\t \t \t def emp = Employee.get(Hmap.get("empId"))
\t \t \t if(emp){
\t \t \t def Username = springSecurityService.getPrincipal().getUsername()
\t \t \t def row = DbUser.findByEmployee(emp)
\t \t \t if(!row){
\t \t \t def data = new DbUser(employee:emp,username:Hmap.get("userName"),password:Hmap.get("password"),client:Hmap.get("client"),create_id:Username,create_dt:new Date(),mod_id:null,mod_dt:null)
\t \t \t data.save(failOnError: true)
\t \t \t return data
\t \t \t }else{
\t \t \t return "exist"
\t \t \t }
\t \t }else{
\t \t return "invalid"
\t \t }
\t \t }
\t \t \t catch(Exception e){
\t \t \t println("Exception in getDbuserDetails() of DbuserService.groovy: "+e);
\t \t \t }
\t \t }
它給了我像
錯誤的錯誤| 2017年2月10日18:44:08307 [HTTP-BIO-8080-EXEC-4] ERROR spi.SqlExceptionHelper - 字段 '僱員' 不具有在getDbuserDetails)DbuserService.groovy的缺省值 的異常(:有機.springframework.dao.DataIntegrityViolationException:Hibernate操作:無法執行語句; SQL [n/a];字段'員工'沒有默認值;嵌套異常是java.sql.SQLException:字段'員工'沒有默認值
錯誤信息: 2017年2月10日18:44:08328 [HTTP-BIO-8080-EXEC-4] ERROR hibernate.AssertionFailure - HHH000099:斷言故障發生(這可指示在休眠中的錯誤,但更可能是由於不安全使用):org.hibernate.AssertionFailure:com.domain.gcg.DbUser條目中的null id(發生異常後不刷新會話)
錯誤信息: 2017-02-10 18:44:08,469 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResolver - 處理請求時發生AssertionFailure:[POST]/UserManagement/dbuser/addDbuserDetails - 參數: 重新輸入密碼:pass123 客戶端:TestClient的 密碼:pass123 EMPID:SE357 empName:Abhilash Shajan 用戶名:在com.domain.gcg.DbUser進入Abhi123 空ID(發生異常後不要衝洗會議)。堆棧跟蹤如下: 消息:com.domain.gcg.DbUser進入空ID(發生異常後不要衝洗會議)
這裏是我DbUser.groovy域類
class DbUser {
\t \t
\t Employee employee
\t String client
\t String username
\t String password
\t String create_id
\t Date create_dt
\t String mod_id
\t Date mod_dt
\t
\t static mapping = {
\t \t version true
\t \t dynamicUpdate true
\t \t password type: GormEncryptedStringType
employee column: '`employee`',generator: 'foreign', params: [ property: 'employee'], insertable: false, updateable: false
}
\t static constraints = {
\t \t mod_id(nullable: true)
\t \t mod_dt(nullable: true)
\t }
有人能幫助我嗎?
這是和以前一樣的問題。您是否嘗試按照我的建議重新創建數據庫? (只是刪除所有表並重新運行Grails應用程序,讓它重新創建表。 –
@MikelisBaltruks我刪除了數據庫,並創建了一個新的一個,但問題仍然存在。:-( –