Creating a Persistence Unit

See Also

A persistence unit is required if you are using Java Persistence in your EJB module or web module.

To create a persistence unit:

  1. In the Projects window, right-click a web or EJB module project node and choose New > Other.
  2. Select Persistence Unit in the Persistence category and click Next.
  3. Specify a unique Persistence Unit Name. In most cases you can keep the default name suggested by the IDE.
  4. Select a persistence provider or library from the drop-down menu, or add a new library by choosing New Persistence Library.
  5. Select a data source from the drop-down menu. The data source can be a JDBC connection or a database connection. To appear in the list, the data source needs to be registered with the IDE.
  6. Select Use Java Transaction APIs if you want the container to manage the entities.
  7. Specify a table generation strategy for your database.
  8. Click Finish.

When you click Finish, the file persistence.xml opens in the Source Editor.

In the IDE, you can find persistence.xml in the Projects window under the Configuration Files node. In the Files window, persistence.xml is located in the src/conf directory.

When packaged, persistence.xml is located in the META-INF directory of an EJB JAR file or the WEB-INF/classes directory of a WAR file.

See Also
Working with Enterprise Applications
About Persistence Units

Legal Notices