You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by MG Ferreira <mg...@ferrasolutions.com> on 2018/08/02 08:10:53 UTC

Wicket and JPA - best place to instantiate EntityManager

Hi there,

I am looking at using Wicket for a project and have done some prototyping. It looks great, but I need a bit of guidance please. I am also new to JPA but have used JaveEE before. Then I used a @Resource tag and did not wonder about what happened under the hood as much as now.

In the prototype I annotated a class with @WebListener and implemented ServletContextListener to instantiate the EntityManager once and then would use this class to get to the singleton EntityManager. It works great but I think I have to rethink what will happen in a multiuser environment. I like this approach as the instantiation happens once and I can probably wrap code inbetween start and end transactions where needed but wonder about scaling and so on. Any suggestions?

I think the alternative is to instantiate the EntityManager as part of a WebPage’s init or maybe somewhere in the request cycle. Can I use the singleton approach above or is there some standard pattern in which an EntityManager is used?

TIA
skaak

Re: Wicket and JPA - best place to instantiate EntityManager

Posted by MG Ferreira <mg...@ferrasolutions.com>.
Of course users@ that is what I was looking for … my mistake and big apologies.

Thanks anyhow for your reply.

> On 02 Aug 2018, at 10:18, Martin Grigorov <mg...@apache.org> wrote:
> 
> Hi,
> 
> Please ask such kind of questions in users@wicket.apache.org.
> dev@ is about developing Wicket itself, not about developing with Wicket.
> 
> About the question:
> Usually applications use JavaEE containers to provide such kind of
> resources or Spring Framework.
> In both cases you need to configure EntityManagerFactory and then use it to
> create EntityManagers for each request.
> 
> On Thu, Aug 2, 2018 at 11:11 AM MG Ferreira <mg...@ferrasolutions.com> wrote:
> 
>> Hi there,
>> 
>> I am looking at using Wicket for a project and have done some prototyping.
>> It looks great, but I need a bit of guidance please. I am also new to JPA
>> but have used JaveEE before. Then I used a @Resource tag and did not wonder
>> about what happened under the hood as much as now.
>> 
>> In the prototype I annotated a class with @WebListener and implemented
>> ServletContextListener to instantiate the EntityManager once and then would
>> use this class to get to the singleton EntityManager. It works great but I
>> think I have to rethink what will happen in a multiuser environment. I like
>> this approach as the instantiation happens once and I can probably wrap
>> code inbetween start and end transactions where needed but wonder about
>> scaling and so on. Any suggestions?
>> 
>> I think the alternative is to instantiate the EntityManager as part of a
>> WebPage’s init or maybe somewhere in the request cycle. Can I use the
>> singleton approach above or is there some standard pattern in which an
>> EntityManager is used?
>> 
>> TIA
>> skaak


Re: Wicket and JPA - best place to instantiate EntityManager

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Please ask such kind of questions in users@wicket.apache.org.
dev@ is about developing Wicket itself, not about developing with Wicket.

About the question:
Usually applications use JavaEE containers to provide such kind of
resources or Spring Framework.
In both cases you need to configure EntityManagerFactory and then use it to
create EntityManagers for each request.

On Thu, Aug 2, 2018 at 11:11 AM MG Ferreira <mg...@ferrasolutions.com> wrote:

> Hi there,
>
> I am looking at using Wicket for a project and have done some prototyping.
> It looks great, but I need a bit of guidance please. I am also new to JPA
> but have used JaveEE before. Then I used a @Resource tag and did not wonder
> about what happened under the hood as much as now.
>
> In the prototype I annotated a class with @WebListener and implemented
> ServletContextListener to instantiate the EntityManager once and then would
> use this class to get to the singleton EntityManager. It works great but I
> think I have to rethink what will happen in a multiuser environment. I like
> this approach as the instantiation happens once and I can probably wrap
> code inbetween start and end transactions where needed but wonder about
> scaling and so on. Any suggestions?
>
> I think the alternative is to instantiate the EntityManager as part of a
> WebPage’s init or maybe somewhere in the request cycle. Can I use the
> singleton approach above or is there some standard pattern in which an
> EntityManager is used?
>
> TIA
> skaak