2012-12-25 4 views
1

, 내가 코드Hibernate가 백킹 빈 <code>edit()</code> 방법에서

public void edit(Entity e) { 
    this.entity = entityService.find(e); 
    this.entity.setLazyList(new ArrayList(this.entity.getLazyList())); 
} 
public Entity getEntity() { 
    return this.entity; 
} 

다음 한 같은 요청에 다시 반환 ArrayList를 함께 PersistentBag 교체, 나는 ArrayList 내 자신으로 변경하여 게으른 목록을 초기화 . 이상한 점은 느린 목록 안의 PersistentBag이 존재하는 즉시 되살아납니다. edit() 방법입니다. 나는이 문제를 찾기 위해 무슨 짓을 :

  1. 편집 방법에 브레이크 포인터를 놓습니다. 발견 후, 나는 발견 된 엔티티의 JVM ID를보고 101이라고 말합니다.
  2. getEntity() 메소드에 중단 점을 넣습니다. edit()이 존재하면 getEntity()이 호출되고 엔터티의 JVM ID는 여전히 101이지만 entity.lazyListArrayList 대신 PersistentBag이됩니다.

내 LazyList는 a에 바인딩됩니다. 이 PersistentBag는 JSF 페이지에서 save 버튼을 누를 때 LazyInitializationException을 발생시킵니다. 예외 (또한 예외를 발생도에서 MyFaces 시험)의 때문에 인 Mojarra이 부분에서 (저장() 호출 백킹 빈에있어서 전) 발생되어

MenuRenderer 라인 365

// No cloned instance so if the modelType happens to represent a 
// concrete type (probably not the norm) try to reflect a 
// no-argument constructor and invoke if available. 
if (targetCollection == null) { 
    //noinspection unchecked 
    targetCollection = 
      createCollection(currentValue, modelType); 
} 

불행히도 PersistentBag이기 때문에 createCollection()은 더 이상 세션 및로드 된 객체를 모르는이 객체의 새 인스턴스를 반환합니다.

답변

0

<f:attribute name="collectionType" value="java.util.ArrayList" /> 내 안에 <h:selectManyCheckBox>이 있고 지연된 예외가 해결되었습니다. 필요가 수동으로 더 이상 ArrayList를 함께 PersistentBag을 변경할 수 없습니다 :

<h:selectManyCheckbox value="#{backingBean.entity.lazyList}"> 
    <f:attribute name="collectionType" value="java.util.ArrayList" /> 
    <f:selectItems value="#{backingBean.allItems}" var="i" itemLabel="#{i.title}"/> 
</h:selectManyCheckbox> 
:

this.entity.setLazyList(new ArrayList(this.entity.getLazyList())); 
이 속성은 (모두 인 Mojarra와에서 MyFaces에서 작동)

대신 요소에 바인딩 원본 형식의 입력이 컬렉션을 사용하는 JSF의 IMPL을 알려줍니다