2010-12-06 49 views
2

我收到一個如下所示的錯誤。這與我的瀑布建立方式有關嗎?哪裏是適合開始調查的地方?現在我有一個角色有許多角色職責。角色責任屬於角色。 RoleDuty只有一個字段,值班,這是一個空字符串。角色具有RoleDuties列表的all-delete-orphan映射。hibernate聲明從grails項目中失敗

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 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>() 


} 
+0

請出示你的角色和RoleDuty類定義 – 2010-12-06 15:16:57

回答

5

Hibernate的錯誤消息「不發生後異常刷新會議」表明,發生在這個會話一個Hibernate相關的異常,但你的代碼捕捉到的異常和繼續使用會議。 Hibernate的API指出,如果Hibernate拋出異常,則必須回滾事務/關閉會話並在新會話中執行任何您想要的操作。

很難從這個堆棧跟蹤和調試確切地說明問題是什麼,Hibernate錯誤涉及試驗和錯誤。我建議你在查找一個異常之前調試你的代碼,並找出如何避免它。