users@jersey.java.net

RE: MySQL + hibernate + jersey + maven + tomcat

From: Igor Rosenberg <igor.rosenberg_at_atosresearch.eu>
Date: Fri, 26 Nov 2010 09:25:53 +0100

Hello,

Thanks for the link
        http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html
indeed, there's a lot of info there that I didn't know. Right now I can't really check it out, but will do very soon, it does seem very helpful and to the point. In the meantime I found David Sells' http://persistentdesigns.com/wp/?page_id=145 , which got me running with MySQL+hibernate+jersey+maven+tomcat. There is a dependency on Spring which I don't understand, and will have to analyse. When I clean things up in my head and in my code, I'll post back here.

Cheers

Igor

-----Original Message-----
From: reno [mailto:reno.rkcrew_at_free.fr]
Sent: jueves, 25 de noviembre de 2010 21:10
To: users_at_jersey.java.net
Subject: Re: MySQL + hibernate + jersey + maven + tomcat

Igor,

did you define the jndi resource in tomcat ?
http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html

in the sample README.html file, the asadmin tool create it on glassfish
(never use it but i suppose that the asadmin create-jdbc-resource
command line create a resource on the server that can be retreive with
jndi).

Hope this help.

S.
> Hello
>
> I've been fighting for some days now with MySQL(5)+hibernate(3.x any will do)+jersey(1.4)+maven(2.2.1)+tomcat(6.0.14).
>
> If there's some great hibernate+jersey+tomcat tutorial out there, point it to me!
>
> First off, what I've done:
>
> I've been able to start a simple REST web-app on tomcat, starting from the examples (bookstore) found in
> http://download.java.net/maven/2/com/sun/jersey/samples/jersey-samples/1.4/jersey-samples-1.4-project.zip
>
> 'mvn tomcat:run' works fine if I include in the pom my tomcat manager's password
> <plugin>
> <groupId>org.codehaus.mojo</groupId>
> <artifactId>tomcat-maven-plugin</artifactId>
> <configuration>
> <username>admin</username>
> <password>XXXXXXXXXXXXX</password>
> </configuration>
> </plugin>
>
> Great start.
>
> Now I thought I'd add hibernate to the soup. I looked at the bookmark example. It uses glassfish and derby... Not having either installed makes it hard to look into the problems that appear. But anyway:
>
> I have changed the persistence file,
> jersey-samples-1.4-project\bookmark\src\main\resources\META-INF\persistence.xml
> to point to my DB:
>
> <persistence-unit name="BookmarkPU">
> <properties>
> <property name="hibernate.archive.autodetection" value="class, hbm" />
> <property name="hibernate.show_sql" value="true" />
> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
> <property name="hibernate.connection.password" value="XXXXXXXXXX" />
> <property name="hibernate.connection.url"
> value="jdbc:mysql://remoteDB:3306/jersey" />
> <property name="hibernate.connection.username" value="jersey" />
> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
> </properties>
> </persistence-unit>
>
> I guess that dependencies on hibernate should be inserted in the pom - but which? I've added some based on some example on the web, and eventually can deploy to tomcat. But I call 'mvn tomcat:run', and try to get the resource at http://localhost:8080/bookmark/resources/users/
> I get a long stacktrace (see below), it's a javax.naming.NameNotFoundException, saying (in Spanish) "El nombre persistence no este asociado a este contexto"
> That translates to "Name persistence is not bound in this Context". The exception is raised when the EntityManager is created:
> $Proxy81.createEntityManager(Unknown Source)
> com.sun.jersey.samples.bookmark.resources.UsersResource.getUsers(UsersResource.java:76)
>
> How can I integrate hibernate with jersey?
>
> I've just changed the persistence-unit properties and included hibernate in the dependencies, what am I missing?
>
> Thanks for helping!
>
> Cheers
> Igor
>
> -------------
>
> javax.naming.NameNotFoundException: El nombre persistence no este asociado a este contexto
> org.apache.naming.NamingContext.lookup(NamingContext.java:770)
> org.apache.naming.NamingContext.lookup(NamingContext.java:140)
> org.apache.naming.NamingContext.lookup(NamingContext.java:781)
> org.apache.naming.NamingContext.lookup(NamingContext.java:140)
> org.apache.naming.NamingContext.lookup(NamingContext.java:781)
> org.apache.naming.NamingContext.lookup(NamingContext.java:153)
> org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
> javax.naming.InitialContext.lookup(InitialContext.java:392)
> com.sun.jersey.server.impl.ThreadLocalNamedInvoker.invoke(ThreadLocalNamedInvoker.java:68)
> $Proxy81.createEntityManager(Unknown Source)
> com.sun.jersey.samples.bookmark.resources.UsersResource.getUsers(UsersResource.java:76)
> com.sun.jersey.samples.bookmark.resources.UsersResource.getUsersAsJsonArray(UsersResource.java:88)
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> java.lang.reflect.Method.invoke(Method.java:597)
> com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:168)
> com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:70)
> com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:279)
> com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:86)
> com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
> com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:74)
> com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1357)
> com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1289)
> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1239)
> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1229)
> com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:497)
> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:684)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>
>
> ------------------------------------------------------------------
> This e-mail and the documents attached are confidential and intended
> solely for the addressee; it may also be privileged. If you receive
> this e-mail in error, please notify the sender immediately and destroy it.
> As its integrity cannot be secured on the Internet, the Atos Origin
> group liability cannot be triggered for the message content. Although
> the sender endeavours to maintain a computer virus-free network,
> the sender does not warrant that this transmission is virus-free and
> will not be liable for any damages resulting from any virus transmitted.
>
> Este mensaje y los ficheros adjuntos pueden contener informacion confidencial
> destinada solamente a la(s) persona(s) mencionadas anteriormente
> pueden estar protegidos por secreto profesional.
> Si usted recibe este correo electronico por error, gracias por informar
> inmediatamente al remitente y destruir el mensaje.
> Al no estar asegurada la integridad de este mensaje sobre la red, Atos Origin
> no se hace responsable por su contenido. Su contenido no constituye ningun
> compromiso para el grupo Atos Origin, salvo ratificacion escrita por ambas partes.
> Aunque se esfuerza al maximo por mantener su red libre de virus, el emisor
> no puede garantizar nada al respecto y no sera responsable de cualesquiera
> danos que puedan resultar de una transmision de virus.
> ------------------------------------------------------------------
>


------------------------------------------------------------------
This e-mail and the documents attached are confidential and intended
solely for the addressee; it may also be privileged. If you receive
this e-mail in error, please notify the sender immediately and destroy it.
As its integrity cannot be secured on the Internet, the Atos Origin
group liability cannot be triggered for the message content. Although
the sender endeavours to maintain a computer virus-free network,
the sender does not warrant that this transmission is virus-free and
will not be liable for any damages resulting from any virus transmitted.

Este mensaje y los ficheros adjuntos pueden contener informacion confidencial
destinada solamente a la(s) persona(s) mencionadas anteriormente
pueden estar protegidos por secreto profesional.
Si usted recibe este correo electronico por error, gracias por informar
inmediatamente al remitente y destruir el mensaje.
Al no estar asegurada la integridad de este mensaje sobre la red, Atos Origin
no se hace responsable por su contenido. Su contenido no constituye ningun
compromiso para el grupo Atos Origin, salvo ratificacion escrita por ambas partes.
Aunque se esfuerza al maximo por mantener su red libre de virus, el emisor
no puede garantizar nada al respecto y no sera responsable de cualesquiera
danos que puedan resultar de una transmision de virus.
------------------------------------------------------------------