users@jersey.java.net

[Jersey] Re: jersey + glassfish + hibernate

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Fri, 18 Nov 2011 16:46:23 +0100

Hi Ole,

Try to use:

@PersistenceUnit(unitName="myPU")

instead of @PersistenceContext(...)

that one should work.

If that fails, please let me know.

~Jakub

On 16.11.2011 15:35, ole wrote:
>
> Hello,
>
> I'm trying to setup a simple RESTful webservice by using jersey.
> Additionally I'm using Glassfish 2 as server and hibernate for
> persistence.
>
> In my JAX-RS resource I'm trying to get a EntityManagerFactory to
> create an EntityManager by using:
>
> @PersistenceContext(unitName="myPU")
>
> EntityManagerFactory emf;
>
> This is not working Lemf is always null.
>
> If I'm using
>
> @GET
>
> @Produces("text/plain")
>
> *public*String getIt() {
>
> EntityManagerFactory emf =
> Persistence./createEntityManagerFactory/( "myPU");
>
> it is working.
>
> I would prefer to inject the emf by using the @PersistenceContext
> annotation. Why it is not working?
>
> Best regards,
>
> ole
>