[jboss-user] [JBoss Seam] - Re: LazyInitializationExceptions are staying

Humber Aquino humberaquino at gmail.com
Thu Sep 13 11:14:23 EDT 2007

Hi Michael.

I don´t know about your problem with the dvd store but i would like to give
you a tip.
The Lazy loading works only with managed entities. That means that you have
to get the entity with the entity manager and use it.
If you have a reference that is persisted but is not attached to a entity
manager you have to merge it.
For example.
If you have a Many to many relationship between an entity named Person and a
entity named Project.
public class Person implements Serializable {
   //id and code

 private List<Project> projects;

//getters and setters

And have an action method that use a person object

public void doSopmething(){
      //this.person is a valid reference to a person object in the session
for example
      // you have to merge it so the entity manager can lazy load the

     Person newReferenceToPerson = entityManager.merge(this.person);
   //now, use the new object that is sincronized with the database.
  // You could rereferenciate the person too.

  List<Project> projects = newReferenceToPerson.getProjects();
  //It lazy loads all projects asociated to this person.


I hope this helps.

On 9/13/07, ASavitsky <do-not-reply at jboss.com> wrote:
> Michel,
> Try injecting your persistence context using @In - I believe that lazy
> loading only works with Seam-managed PC (the one injected via
> @PersistenceContext is not Seam-managed). Of course, you'll need to setup
> the SMPC properly as well... (look at examples)
> HTH,
> Alex
> View the original post :
> http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4084001#4084001
> Reply to the post :
> http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4084001
> _______________________________________________
> jboss-user mailing list
> jboss-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/jboss-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20070913/85527927/attachment.html 

More information about the jboss-user mailing list