开发者

hibernate AssertionFailure from a grails project

I am getting an error that begins as follows below. Is this something to do with the way my cascades are set up? Where is the proper place to start investigating? Right now I have a Role which hasMany RoleDuty. RoleDuty belongsTo Role. RoleDuty only has one field, duty, which is a nullable String. Role has a mapping of all-delete-orphan for the RoleDuties list.

06.12.2010 10:02:17 *ERROR* AssertionFailure: an assertion failure occured (this may indicate a bug in Hibernate, but is
 more likely due to unsafe use of the session) (AssertionFailure.java, line 47)
org.hibernate.AssertionFailure: null id in RoleDuty entry (don't flush the Session after an exception occurs)
        at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:78)
        at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:187)
        at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:14
3)
        at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
        at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListen
er.java:99)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:49)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
        at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
        at org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewInterceptor.flushIfNecessary(GrailsOp
enSessionInViewInterceptor.java:116)
        at org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor.postHandle(OpenSessionInViewIntercept
or.java:181)
        at org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewInterceptor.postHandle(GrailsOpenSess
ionInViewInterceptor.java:66)
        at org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter.postHandle(WebRequestHandlerInter
ceptorAdapter.java:61)
     开发者_高级运维   at org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:303)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

Class definitions:

class RoleDuty
{


  static belongsTo = [role:Role]

  static constraints = {
        duty(nullable: true)
  } 
    static mapping = {
          duty type:"text"
    }

  String duty;
  boolean _deleted
  static transients = ['_deleted']

  @XmlValue
  public String getDuty(){
    return duty;
  }


  String toString()
  {
      return duty;
  }

}


public class Role implements Comparable
{

    static belongsTo = [project:Project]
    static hasMany = [ roleDuties:RoleDuty]

    static mapping = {
        roleDuties cascade:"all-delete-orphan", lazy:false
    }

    List<RoleDuty> roleDuties = new ArrayList<RoleDuty>()


}


Hibernate's error message "don't flush the Session after an exception occurs" suggests that a Hibernate-related exception occurred on this Session but your code caught the exception and continued to use the Session. Hibernate's API states that if Hibernate throws an exception, you must roll back the transaction/close the Session and do whatever you want in a new Session.

It's hard to tell exactly what the issue is from just this stack trace and debugging Hibernate errors involves trial and error. I suggest you debug your code while looking for an exception prior to this one and figure out how to avoid it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜