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 <[email protected]> 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>)
>>
>>
>> best regards, Andreas Lundblad
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: 
>> users-unsubscribe@wicket.**apache.org<[email protected]>
>> For additional commands, e-mail: [email protected]
>>
>>
>

Reply via email to