-
1. Re: why EntityManager is closed?
swd847 Mar 11, 2009 9:43 AM (in response to akopylov)The entityManager is Conversation scoped, while your bean is session scoped. This means that after the conversation that created the bean is over, the entityManager will be closed.
You should not store references to conversation scoped components inside a session scoped component (actually you should not store references to components at all). Instead they should be injection each time using @In.
-
2. Re: why EntityManager is closed?
akopylov Mar 11, 2009 9:48 AM (in response to akopylov)
You should not store references to conversation scoped components inside a session scoped component (actually you should not store references to components at all). Instead they should be injection each time using @In.Can you show me simple example how to do it with EntityManager?
-
3. Re: why EntityManager is closed?
swd847 Mar 11, 2009 9:52 AM (in response to akopylov)put this inside your component:
@In EntityManaqer entityManager;
That will inject the entityManager every time you invoke a method on the component
-
4. Re: why EntityManager is closed?
akopylov Mar 11, 2009 10:01 AM (in response to akopylov)
Stuart Douglas wrote on Mar 11, 2009 09:52:
put this inside your component:@In EntityManaqer entityManager;
That will inject the entityManager every time you invoke a method on the componentI put this string in my bean. And IDE showed me this message:
Undefined context variable 'entityManager'What is the problem? What should I do to solve it? May be I need some additional adjustments.
-
5. Re: why EntityManager is closed?
swd847 Mar 11, 2009 10:12 AM (in response to akopylov)In your components.xml you should have a line similar to:
<persistence:manager-persistence-context name="entityManager" />
if your name is different rename the variable in the bean to whatever you called your entityManager. If it is called entityManager then just hit the run button and ignore the IDE error messsage.
-
6. Re: why EntityManager is closed?
akopylov Mar 11, 2009 10:52 AM (in response to akopylov)Yes. It's working. Thanks a lot.
I think, the message of IDE is bug of IDE. Because injection of EntityManager is working.And a last number of questions. As I uderstand, in session-scoped beans I must use setEntityManager method every time when I want to refresh data in EntityQuery. Is this true?
But how about extending EntityController in session-scoped bean? -
7. Re: why EntityManager is closed?
swd847 Mar 11, 2009 11:45 AM (in response to akopylov)Actually you should probably be injecting the EntityQuery using @In. You are going to have to post more details about what you are trying to achieve. Keeping entities lying around in session scope can be problematic because they will eventually become detached, which may cause problems depending on what you are trying to do.