代码之家  ›  专栏  ›  技术社区  ›  mph

HibernateException:当前没有会话绑定到执行上下文

  •  1
  • mph  · 技术社区  · 15 年前

    我试图用Grails和Postgres创建一个非常基本的REST-ish web服务。我让read()&delete()方法工作,但无法让create()工作。Hibernate只是抱怨,“HibernateException:No session currently bind to execution context.”下面是我的创建方法:

    def create = {
      def member = new Member(params)
      member.save()
      render(status: 201)
    }
    

    任何建议都很好。谢谢。

    1 回复  |  直到 15 年前
        1
  •  1
  •   cнŝdk    9 年前

    问题解决了!

    因为我有EJB3注释文件作为Grails域类,所以我必须为映射创建自己的hibernate.cfg.xml。我试着改变

    <property name="current_session_context_class">org.hibernate.context.ManagedSessionContext</property>
    

    <property name="current_session_context_class">thread</property>
    

    它们都产生了Hibernate会话错误。后来我终于发现 this discussion 这意味着您根本不应该在Hibernate配置文件中包含此属性。