2017-05-20 5 views
0

<>org.hibernate.LazyInitializationException:怠惰な役割のコレクションを初期化に失敗しました:

これがあるの一覧を表示する> HashSetの<をconvetしようとしたとき、私はこのエラーに

org.hibernate.LazyInitializationException: 
failed to lazily initialize a collection of role: com.InventoryProject.Entity.Decharge.produits, 
could not initialize proxy - no Session 

を取得しています

:機能

public void SaveToPrint() throws Exception{ 


     int id_decharge = ServiceFactory.getDechargeservice().derniereDecharge(); 
     Decharge decharge = ServiceFactory.getDechargeservice().FindDecharge(id_decharge); 
     decharge.setObservations(obsrv); 
     ServiceFactory.getDechargeservice().ModifierDecharge(decharge); 

     Set<Produit> liste = new HashSet<Produit>(); 
     liste = ServiceFactory.getDechargeservice().getDechargeById(id_decharge).getProduits(); 

     liste_produits= new ArrayList<Produit>(liste); 

     ServiceFactory.getProduitservice().supprimerConsomable(); 

     FacesContext.getCurrentInstance().addMessage(null, 
       new FacesMessage(FacesMessage.SEVERITY_INFO, "Info", "Opération terminé")); 
    } 

は私がでexactylyエラーを取得しています

liste_produits= new ArrayList<Produit>(liste); 

これは、あなたがこの問題を解決することができます

<hibernate-mapping> 
    <class name="com.InventoryProject.Entity.Decharge" table="DECHARGE"> 
     <meta attribute="class-description"> 
     This class contains the product detail. 
     </meta> 
     <id name="id" type="int" column="ID_DECHARGE"> 
     <generator class="native"/> 
     </id> 
     <property name="beneficiaire" column="BENEFICIAIRE" type="string"/> 
     <property name="observations" column="OBSERVATIONS" type="string"/> 
     <property name="type" column="TYPE" type="string"/> 
     <property name="prix" column="PRIX" type="int"/> 
     <property name="date" column="DATE" type="string"/> 

     <set name="produits" table="PR_DECHARGE"> 
     <key column="ID_DECHARGE"></key> 
     <many-to-many class="com.InventoryProject.Entity.Produit" column="ID_PRODUIT"></many-to-many> 
     </set> 
    </class> 
</hibernate-mapping> 

マッピングファイルのですか?ありがとうございました。

+0

[org.hibernate.LazyInitializationException - プロキシを初期化できませんでした - なしセッション]の可能な重複(http://stackoverflow.com/questions/21574236/org-hibernate-lazyinitializationexception-could-not-initialize -proxy-no-sess) –

答えて

関連する問題