Hi Lucas,
1) what jars do i need?
Your classpath needs to have following.
${GLASSFISH_INSTALL}/lib/toplink-essentials.jar
${GLASSFISH_INSTALL}/lib/asm.jar
${GLASSFISH_INSTALL}/lib/asm-attrs.jar
${GLASSFISH_INSTALL}/lib/antlr.jar
${GLASSFISH_INSTALL}/lib/javaee.jar
<your database driver jar>
<application classes>
2) what does a persistence.xml file really look like?
Please have a look at Look at persistence.xml.template file packaged in classes/META-INF dir of the example at
https://glassfish.dev.java.net/javaee5/persistence/persistence-example.html
3) where exactly must a persistence.xml file go?
For the example, the file needs to be in classes/META-INF directory. Please have a look at Chapter 6 of Java Persistence API spec for more details.
4) how can I automatically generate the tables for my POJOs to be stored in?
You need to add a property "ddl-generation" to your persistence.xml as follows
<property name="ddl-generation" value="dropandcreate"/>
Please look at an excellent blog <
http://blogs.sun.com/roller/page/java2dbInGlassFish> by Pramod on automatic schema generation for more information
5) Is there official/current documentation?
The most comprehensive document is the JSR 220 spec.
6) can I use Derby running as a separate server as a store? if so, how?
Definitely. You need to start derby in networkserver mode. The easiest way to achieve this with the bundled derby is "asadmin start-database". Please refer to derby docs <
http://db.apache.org/derby/manuals/> for more details
Following is a sample persistence.xml that can be used to connect to derby running on localhost
<persistence ..... >
<persistence-unit .... >
<provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
.
.
<properties>
<!-- JDBC connection properties -->
<property name="jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="jdbc.connection.string" value="jdbc:derby://localhost:1527/testdb;retrieveMessagesFromServerOnGetMessage=true;create=true;"/>
<property name="jdbc.user" value="yourusername"/>
<property name="jdbc.password" value="yourpassword"/>
<property name="ddl-generation" value="dropandcreate"/>
.
.
.
</properties>
</persistence-unit>
.
.
.
</persistence>
The example works correctly when -javaagent is used. It will throw a NPE when used without -javaagent. This is a known issue <
https://glassfish.dev.java.net/issues/show_bug.cgi?id=101>. A work around is to pass a HashMap to createEntityManagerFactory() method as noted in the issue
EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu1", newHashMap());
We are working on a example with ant scripts to build and run the example. Hopefully this would make it easier to run the example.
In future, please post to persistence@glassfish.dev.java.net or forums <
http://forums.java.net/jive/forum.jspa?forumID=56&start=0> to get a faster response.
Thanks,
Mitesh
>
>
> ------------------------------------------------------------------------
>
> Subject:
> step by step directions Persistence API J2SE
> From:
> Lucas Jordan <lucas.jordan_at_childrens.harvard.edu>
> Date:
> Mon, 09 Jan 2006 16:13:49 -0500
> To:
> users_at_glassfish.dev.java.net
>
> To:
> users_at_glassfish.dev.java.net
>
>
> have tried a bunch of blog/tutorials trying to get the new Persistence API
> working from j2se. I have been unable find a basic working example.
>
> What I want to know is:
> 1) what jars do i need?
> 2) what does a persistence.xml file really look like?
> 3) where exactly must a persistence.xml file go?
> 4) how can I automatically generate the tables for my POJOs to be stored in?
> 5) Is there official/current documentation?
> 6) can I use Derby running as a separate server as a store? if so, how?
>
> I would really appreciate anyone helping me, I'm really tired of looking at
> the same outdated examples :)
>
> I was looking at:
> https://glassfish.dev.java.net/javaee5/persistence/persistence-example.html
>
> But the example download for j2se is busted. Also it calls for using the
> javaagent (-javaagent:${glassfish.home}/lib/toplink-essentials-agent.jar)
> command, is this actually required?
>
>
> -Lucas
>
> P.S. what is wrong when I get a stack trace that looks like:
> Exception in thread "main" java.lang.NullPointerException
> at
> oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.callPredepl
> oy(JavaSECMPInitializer.java:120)
> at
> oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.initPersist
> enceUnits(JavaSECMPInitializer.java:279)
> at
> oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.initialize(
> JavaSECMPInitializer.java:298)
> at
> oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.initializeF
> romMain(JavaSECMPInitializer.java:335)
> at
> oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.getJavaSECM
> PInitializer(JavaSECMPInitializer.java:78)
> at
> oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.getServerSes
> sion(EntityManagerFactoryProvider.java:235)
> at
> oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createEntity
> ManagerFactory(EntityManagerFactoryProvider.java:94)
> at
> javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61
> )
> at
> javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:50
> )
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>