开发者

No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

In controller :

AssocCovList.addAssoc(3, 4)

In Domain :

package com.org.domain
class AssocCovList {
    Integer id
    Integer association_id
    Integer cov_list_id
    Date edit_date

    static belongsTo = [association : Association, cov_list : CoverageList]

    static constraints = {
        edit_date(nullable:true )
    }

    static mapping = {
        table 'assoc_cov_list'
        version false
        columns {
        id column : 'ASSOC_COV_LIST_ID'
        association_id column : 'ASSOCIATION_ID'
        cov_list_id column : 'COV_LIST_ID'
        edit_date column : 'EDIT_DATE'
        }
    }


def static addAssoc(3, 4){
   def aclist = new Assoc开发者_运维百科CovList(association_id:3,cov_list_id:4, edit_date:new Date())
   aclist.save()
}

Here is sql structure :

CREATE TABLE omni.assoc_cov_list (

ASSOC_COV_LIST_ID int(11) NOT NULL auto_increment,

ASSOCIATION_ID smallint(6) NOT NULL default '0',

COV_LIST_ID int(11) NOT NULL default '0',

EDIT_DATE date default NULL,

PRIMARY KEY (ASSOC_COV_LIST_ID),

UNIQUE KEY ASSOC_COV_LIST_I2 (ASSOCIATION_ID,COV_LIST_ID),

KEY ASSOC_COV_LIST_FK1 (COV_LIST_ID),

KEY ASSOC_COV_LIST_FK2 (ASSOCIATION_ID)

) ENGINE=InnoDB AUTO_INCREMENT=9584 DEFAULT CHARSET=utf8;

This was returning No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

Why it is returning null object? I am able to update and delete the record(s). Not working for new record.


Wait a minute... I think the domain class itself is not the right place to call a save() on itself ! This should be done at the controller or service level. Can you give a try to this :

In your domain class :

def static addAssoc(<yourargs>){
    return new AssocList(/*Whatever arguments you pass */)
}

In your controller :

AssocCovList.addAssoc(<yourargs>).save()    


You defined AssocCovList to have the following properties:

Integer id
Integer association_id
Integer cov_list_id
Date edit_date

And then try to create a new AssocCovList(association_id:3) using only the association_id. However, by default all properties are both persistent and required. To create a new AssocCovList you would need to provide also the id, cov_list_id and edit_date.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜