users@jersey.java.net

Re: [Jersey] Bookmark Jersey Example

From: Arun Gupta <Arun.Gupta_at_Sun.COM>
Date: Fri, 16 Oct 2009 08:07:31 -0700

Hi Paul,

Here is a simple blog entry that explains how to use JPA in a Java EE 6
app using NetBeans:

http://blog.arungupta.me/2009/10/totd-108-java-ee-6-web-application-jsf-2-0-jpa-2-0-ejb-3-1-using-oracle-netbeans-and-glassfish/

Essentially, EntityManager* can be injected in any server side artifact as:

@PersistenceContext
  EntityManager em;

or

@PersistenceUnit
EntityManagerFactory emf;

When to use which one is explained at:

http://blog.arungupta.me/2009/08/lotd-22-how-to-inject-jpa-resources-persistenceunit-vs-persistencecontext/

I'll try running this exact sample on GFv3 and report back.

Thanks,
-Arun

Paul Sandoz wrote:
> Hi Roan,
>
> Unfortunately i do not understand enough about persistence configuration.
>
> Fundamentally once an EntityManagerFactory is available in JNDI Jersey
> should be able to make use of it.
>
> All the head scratching is working out how to configure the persistence
> stuff and DB, i must admit i find it infuriating and i am sure you do to!
>
> Pavel (another Jersey team member) is doing some investigations and the
> bookmark sample works fine on GF v2.1. But we cannot get it to work
> properly on GF v3.
>
>
> I am also CC'ing Arun who has presented blog-based tutorials on using
> Java EE with MySQL. Arun, if you have some free time, could you help
> Pavel and Roan get a version of the bookmark sample [1] working on GF v3
> with MySQL?
>
> Paul.
>
> [1] http://download.java.net/maven/2/com/sun/jersey/samples/bookmark/1.1.3-ea/bookmark-1.1.3-ea-project.zip
> Note if using this sample with GF v3 modify the jersey dependencies
> in the pom.xml so that the scope is
> provided.
>
> On Oct 15, 2009, at 7:20 PM, Roan Brasil Monteiro wrote:
>
>> When I am changing to usr Mysql the Bookmark Jersey Example I have my
>> persistence.xml
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <persistence version="1.0"
>> xmlns="http://java.sun.com/xml/ns/persistence"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
>> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
>> <persistence-unit name="BookmarkPU" transaction-type="JTA">
>> <provider>org.hibernate.ejb.HibernatePersistence</provider>
>> <!--
>> <provider>oracle.toplink.essentials.PersistenceProvider</provider>
>> <properties>
>> <property name="toplink.jdbc.url"
>> value="jdbc:derby://localhost:1527/BookmarkDB;create=true"/>
>> <property name="toplink.jdbc.user" value="REST"/>
>> <property name="toplink.jdbc.driver"
>> value="org.apache.derby.jdbc.ClientDriver"/>
>> <property name="toplink.jdbc.password" value="REST"/>
>> <property name="toplink.ddl-generation" value="create-tables"/>
>> </properties> -->
>> <properties>
>> <property name="hibernate.dialect"
>> value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
>> <property name="hibernate.hbm2ddl.auto" value="update"/>
>> <property name="hibernate.show_sql" value="true"/>
>> <property name="hibernate.format_sql" value="true"/>
>> <property name="hibernate.connection.characterEncoding"
>> value="UTF-8"/>
>> <property name="hibernate.connection.driver_class"
>> value="com.mysql.jdbc.Driver"/>
>> <property name="hibernate.connection.url"
>> value="jdbc:mysql://localhost:3306/jpa;create=true"/>
>> <property name="hibernate.connection.username" value="root"/>
>> <property name="hibernate.connection.password"
>> value="spacecite"/>
>> </properties>
>> </persistence-unit>
>> </persistence>
>>
>>
>>
>> I keep the web.xml the same.
>>
>> When I am deploying I am getting
>>
>> Command deploy executed successfully with following warning messages:
>> Error occurred during application loading phase. The application will
>> not run properly. Please fix your application and redeploy.
>> WARNING: com.sun.enterprise.deployment.backend.IASDeploymentException:
>> org/dom4j/DocumentException
>>
>>
>> I dont know what happenned but I have this jar in my project. Can
>> someone help me plse?
>>
>> --
>> Atenciosamente,
>>
>> Roan Brasil Monteiro
>> http://roanbrasil.wordpress.com/
>

-- 
Need Application Server ? Download from http://glassfish.org
Blog: http://blog.arungupta.me