-
1. Re: LazyInitializationException
dhinojosa Jun 27, 2008 5:56 PM (in response to benitojuarez)You are likely accessing the collection when the persistence session is closed.
-
2. Re: LazyInitializationException
benitojuarez Jun 27, 2008 6:00 PM (in response to benitojuarez)ok, but how can i open the session in my template?
-
3. Re: LazyInitializationException
dhinojosa Jun 27, 2008 6:47 PM (in response to benitojuarez)Your template?
There's not construct in Seam called a template. Unless you use seam gen's template.xhtml, but I don't think you are referring to that.
Your persistence session is usually defined by the scope of your entity and the scope of your session bean. So what are those scopes?
-
4. Re: LazyInitializationException
gjeudy Jun 27, 2008 7:29 PM (in response to benitojuarez)Are you using SMPC ? (Seam managed persistence context)
It sounds like you are not familiar with persistence contexts, I suggest you read up relevant docs on this.
See: Seam managed persistence contextsIf you use SMPC then your persistence context is scoped to the conversation by default. What you are attempting to do is lazy initialize an entity that is no longer managed by it's persistence context (it is in a detached state) because the conversation in which the entity was originally loaded has ended.
When Seam ends a conversation it will also close the SMPC.
-
5. Re: LazyInitializationException
benitojuarez Jun 29, 2008 3:16 PM (in response to benitojuarez)Hello,
It sounds like you are not familiar with persistence contexts, I suggest you read up relevant docs on this.
it's the truth, i'm not familiar to the persistence contexts yet. So please be patience.
I solved the problem using
@In private EntityManager entityManager;
instead of @PersistenceContext.
thx for the link
BJ -
6. Re: LazyInitializationException
admin.admin.email.tld Jun 29, 2008 5:48 PM (in response to benitojuarez)It's recommended to use @In to inject the EntityManager in Seam components.
You could also use the extended PersistenceContext:
@PersistenceContext(type=PersistenceContextType.EXTENDED) EntityManager em;
The dvdstore example in the distro is using the above code to inject the EntityManager. Most likely you were using the default Transaction type.
from Hibernate docs:
You can also use an extended persistence context. This can be combined with stateful session beans, if you use a container-managed entity manager: the persistence context is created when an entity manager is retrieved from dependency injection or JNDI lookup , and is kept until the container closes it after the completion of the Remove stateful session bean method. This is a perfect mechanism for implementing a
long
unit of work pattern. For example, if you have to deal with multiple user interaction cycles as a single unit of work (e.g. a wizard dialog that has to be fully completed), you usually model this as a unit of work from the point of view of the application user, and implement it using an extended persistence context.
see link