Here are some discussions:
http://stackoverflow.com/questions/10431640/guice-persist-attempting-to-execute-an-operation-on-a-closed-entitymanager
http://stackoverflow.com/questions/14585505/jpa-guice-persist-permanently-opened-connection-issue


On Thu, Jun 27, 2013 at 3:20 PM, Bas Gooren <b...@iswd.nl> wrote:

> I agree; Since the EntityManager is bound to the request (scope), it's
> usually better to inject Provider<EntityManager>
>
> However, in the demo project the service is not a singleton, so it should
> be fine. A new instance of the service is created for every injection.
>
>
> Met vriendelijke groet,
> Kind regards,
>
> Bas Gooren
>
> Op 27-6-2013 9:10, schreef Martin Grigorov:
>
>> Hi,
>>
>> I'm not sure whether this is the best solution but you can inject a
>> Provider:
>>
>> @Inject
>> private Provider<EntityManager> em;
>>
>> ...
>>
>> em.get().find(...);
>>
>>
>> On Thu, Jun 27, 2013 at 9:36 AM, Bas Gooren <b...@iswd.nl> wrote:
>>
>>  Hi,
>>>
>>> Looking at the github project you refer to, it should work.
>>> The GuiceComponentInjector which is set-up in the wicket application
>>> injects proxies. That means that when your form is submitted (and a
>>> second
>>> request is made), a new service instance is created.
>>>
>>> So if it's not working for you, there is probably another problem with
>>> your code.
>>> Can you show us some relevant parts of your code, e.g. the validator and
>>> the page which contains the validator?
>>>
>>> Met vriendelijke groet,
>>> Kind regards,
>>>
>>> Bas Gooren
>>>
>>> Op 26-6-2013 22:32, schreef Andreas Lundblad:
>>>
>>>   I've just started using Wicket (I'm half way through Wicket in Action).
>>>
>>>> I've run into the following problem with a user registration form: In
>>>> order to make sure that the provided e-mail is not already registered
>>>> I've written a "UniqueEmailValidator" which I attach to the email
>>>> field. This validator needs access to the DB-service to query the
>>>> database for already registered email-adresses.
>>>>
>>>> The problem is that the DB-service is injected when the registration
>>>> page is created and since I'm using open-session-in-view, the
>>>> DB-service EntityManager is closed after the page is rendered. This
>>>> causes an
>>>>
>>>>     IllegalStateException: EntityManager is closed
>>>>
>>>> once the form is submitted in a subsequent request. (Since the same
>>>> old DB-service object is used in the second request.)
>>>>
>>>>
>>>> (I had the same problem when trying to inject the DB-service in the
>>>> session-object. The same DB-service object was used in multiple
>>>> requests causing the IllegalStateException.)
>>>>
>>>>
>>>> I figured this must be a fairly common problem but can't for my life
>>>> find any solutions in the archives or through googling. I'm curious
>>>> what the best practice is to solve this.
>>>>
>>>>
>>>> (My project builds upon the code available here:
>>>> http://github.com/javadev/****wicket-guice-demo<http://github.com/javadev/**wicket-guice-demo>
>>>> <http://**github.com/javadev/wicket-**guice-demo<http://github.com/javadev/wicket-guice-demo>
>>>> >)
>>>>
>>>>
>>>> best regards, Andreas Lundblad
>>>>
>>>> ------------------------------****----------------------------**
>>>> --**---------
>>>> To unsubscribe, e-mail: 
>>>> users-unsubscribe@wicket.**apa**che.org<http://apache.org>
>>>> <users-unsubscribe@**wicket.apache.org<users-unsubscr...@wicket.apache.org>
>>>> >
>>>>
>>>> For additional commands, e-mail: users-h...@wicket.apache.org
>>>>
>>>>
>>>>
>

Reply via email to