[LazyInitializationException] failed to lazily initialize a collection of role

1,167 views
Skip to first unread message

Sahli Sabrina

unread,
Jun 11, 2013, 9:26:45 AM6/11/13
to google-we...@googlegroups.com
Hi everyOne,
when i try to get a list of object in "Societe" class 


i'm getting this exception
 

LazyInitializationException] failed to lazily initialize a collection of role: com.protid.prosa.shared.model.bo.Commune.soumission, no session or session was closed
[INFO] org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.protid.prosa.shared.model.bo.Commune.soumission, no session or session was closed


Notice that the class Societe have an attribute of type Adresse. the adresse has an attribute Commune . A set of "Soumission" are declared in Commune class by the annotation OneToMany like this

@OneToMany(fetch = FetchType.LAZY, mappedBy="commune",targetEntity=com.protid.prosa.shared.model.bo.Soumission.class)
@Cascade(value = {CascadeType.ALL })
private Set<Soumission> soumission =new HashSet<Soumission>();

public Set<Soumission> getSoumission(){
    return soumission;
}
 
}


i don't get where is the problem because i'm not looking  for the "soumission " objects in the Commune class !!!


here is my rpc cal function



private void getCompany(){
       
        SocieteServiceAsync rpc=clientFactory.getSocieteservicerpc();
          
 
        AsyncCallback<List<Societe>> callback = new AsyncCallback<List<Societe>>() {           
            public void onFailure(Throwable caught) {
                       
                       }
                     
                     
                    public void onSuccess(List<Societe> result) {
                         
                          if(result!=null){
                              societe=result.get(0);
                               result.get(0).getNomsociete();
                       
                          }
                    
                    }
                    };
                   
                rpc.list(callback);
 
                    
    }


Please help,

Thank you

Juan Pablo Gardella

unread,
Jun 11, 2013, 9:31:05 AM6/11/13
to google-we...@googlegroups.com
If you don't want use DTO pattern to transfer objects to UI, check this thread. I've implemented a filter that you can use to put null lazy relationships.

The problem is very common in Hibernate, check in google. It happens when you serialize the object with GWT-RPC.


2013/6/11 Sahli Sabrina <sahli....@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Sahli Sabrina

unread,
Jun 11, 2013, 10:30:18 AM6/11/13
to google-we...@googlegroups.com

Sahli Sabrina

unread,
Jun 11, 2013, 10:52:48 AM6/11/13
to google-we...@googlegroups.com
i  did'nt find the filter in your code . can you explain me please how did you do?

thank you


2013/6/11 Sahli Sabrina <sahli....@gmail.com>
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsub...@googlegroups.com.

Juan Pablo Gardella

unread,
Jun 11, 2013, 10:57:31 AM6/11/13
to google-we...@googlegroups.com

Sahli Sabrina

unread,
Jun 11, 2013, 11:09:24 AM6/11/13
to google-we...@googlegroups.com
Thank you a lot , can you explain me please how it works and how to use it? because  i don"nt use gin so i can't make the difference in code


2013/6/11 Sahli Sabrina <sahli....@gmail.com>


2013/6/11 Sahli Sabrina <sahli....@gmail.com>
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.

Juan Pablo Gardella

unread,
Jun 11, 2013, 11:15:36 AM6/11/13
to google-we...@googlegroups.com

Sahli Sabrina

unread,
Jun 11, 2013, 11:48:30 AM6/11/13
to google-we...@googlegroups.com
OK thank you :) , actually i resolved the problem by creating an extension of the service in wish i override the function list like this



    public List<Societe> list() throws ServiceException {
         List<Societe> list = new ArrayList<Societe>();
         List<Societe>    societes=new ArrayList<Societe>();
            log.debug("debut de la recherche des objets    Societe ");
            try {
                 list = getSocieteDao().list();
 
           
            if(list!=null){
                for(Societe societe :list){
                Societe s=new Societe();
                s.setNomsociete(societe.getNomsociete());
                societes.add(s);
                }
            }
                log.debug("fin de recherche des objets Societe ");
            } catch (Exception re) {
                log.error("erreur de recherche ", re);
                throw new ServiceException(
                        "error lors de la recherche de l'objet Societe : "
                                + re.toString());
            }
            return societes;
     }
    


but i will use dto , i think it is better


thank you again
Reply all
Reply to author
Forward
0 new messages