2011-01-27 10 views
3

안녕하세요, 저는 m : mdb 관계로 GRAILS 응용 프로그램을 구축하고 있습니다. 항목을 표시하려고 할 때 "lazily 역할 모음을 초기화하지 못했습니다 ... 세션이나 세션이 닫히지 않았습니다"오류가 표시됩니다.지연 컬렉션을 지연 초기화하지 못했습니다.

한 클래스입니다 :

class Hazzard{ 

static hasMany = [warning:Warning] 

static constraints = { 
    text(size:1..5000) 
} 

    String name 
    String text 
    String toxicity 
} 

다른 :에서

class Warning{ 

static hasMany = [hazzard:Hazzard] 
static belongsTo = Hazzard 

static constraints = { 
    text(size:1..5000) 
} 

    String code 
    String text 
} 

다른쪽으로/다음과 같은 코드가 작동 보여 좋은

<g:each in="${hazzardInstance.warning}" var="p"> 
<li><g:link controller="Warning" action="show" id="${p.id}">${p?.encodeAsHTML()}</g:link></li> 
</g:each> 

하지만, 다음과 같은 코드가 제공됩니다 다른 페이지에

오류 :

<g:set var="haz" value="${Hazzard.get(params.id)}" /> 
<h1>${haz.name}</h1> 
<p>${haz.text}</p> 
<h1>Toxiciteit</h1> 
<p>${haz.toxicity}</p> 
<br/> 
<h1>Gevaren(H) en voorzorgen(P)</h1> 
<g:each in="${haz.warning}" var="p"> --> This is where the error pops-up 
    ${p.text} 
</g:each> 

이것이 실패한 곳의 단서가 있습니까?

+0

어떤 Grails 버전을 사용하고 있습니까? –

+0

GRAILS 버전을 사용하고 있습니다 : 1.3.6 – BadSkillz

답변

2

컨트롤러에서 get을 수행하고 발견 된 도메인 개체를 렌더링 용보기로 전달하는 것이 더 바람직한 방법입니다. 같은 뭔가 : 그 같은 많은 문제가 Grails에의 최신 버전에서 수정 된했다고 생각하지만,보기에 GORM 조회를 수행

// MyController.groovy 
class MyController { 
    def myAction = { 
     def haz = Hazzard.get(params.id) 
     render(view: 'myview', model: [hazzardInstance: haz]) 
    } 
} 

// my/myview.gsp (the view from your second GSP code block) 
<h1>${hazzardInstance?.name.encodeAsHTML()}</h1> 
... 
<h1>Gevaren(H) en voorzorgen(P)</h1> 
<g:each in="${hazzardInstance?.warning}" var="p">...</g:each> 

때때로, 당신이 받고있는 예외가 발생할 수 있습니다. 그럼에도 뷰를 쿼리하고 렌더링하는 데보다 정확한 관용구를 사용하면이 오류를 방지하는 데 도움이됩니다.

+0

Spot-on은 꿈처럼 작동합니다! – BadSkillz