0

I'm using the internal glassfish 3.1 plugin for Eclipse, along with a derby database I installed (it shows up on the datasource explorer in the Database Developer view in Eclipse), and I'm fumbling at the "last" step of getting the ORM working so that I can develop an app that persists data with EJBs using Eclipselink for the JPA implementation.

I know I need to configure the persistence.xml file, but I'm at a loss for what needs to be in it, what the individual field names mean. I feel like the purpose of the persistence.xml is to tell Glassfish where to find the database to store everything in, and which JPA implementation to use to do that storing.

I have a bunch of questions.

  1. Do I have to have a persistence entry for each class that represents an object in the database? So if I had a Book class and a Library class, would I need two enteries in persistence.xml or could I just do one case that services them both?

  2. Where can I find more information about how to configure the persistence.xml file IN GENERAL. I have found tons of very specific tutorials with information on how to configure it in X, Y, or Z setting, but nothing that explains the individual bits, and how you'd configure them from a high level.

  3. Once I've setup my persistence.xml file correctly, what else do I need to do to ensure that my @annotated classes are going to be serviced by the ORM implementation correctly? Is there something I need to configure in Glassfish?

Jazzepi
  • 5,259
  • 11
  • 55
  • 81

1 Answers1

0

I'm not an expert but...

1) Yes, in my experience you need an entry for each class. There could be exceptions to this but I am unfamiliar with them.

2) [http://wiki.eclipse.org/EclipseLink/] is a good place to start. [http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Configuration/JPA/persistence.xml] has some details that you may already know. I've have trouble finding a perfect resource myself. I've tended to find information fragmented all over the place.

3) In general most of my persistence.xml file has been generated automatically by eclipselink. After I creating a connection pool and JDBC resource from the glassfish Administration Console I had to add my

<jta-data-source>jdbc/your_name</jta-data-source>

to persistence.xml.[1]

<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>

I added these properties so my identity columns would auto-increment using JPA.

Try these two tutorials to get a better understanding of how it works:

[1] http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/#heading_toc_j_24

http://itsolutionsforall.com/index.php

[*apologies I can't post more than 2 links at the moment]

feargal
  • 2,655
  • 2
  • 22
  • 27