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:
- In the Projects window, right-click a web or EJB module project node and choose New > Other.
- Select Persistence Unit in the Persistence category and click Next.
- Specify a unique Persistence Unit Name.
In most cases you can keep the default name suggested by the IDE.
- Select a persistence provider or library from the drop-down menu, or add a new library by choosing New Persistence Library.
- 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.
- Select Use Java Transaction APIs if you want the container to manage the entities.
- Java Transaction APIs are only available if you are deploying to a Java EE 5 container.
If you are not deploying to a Java EE 5 container, the transaction needs to be managed by the application.
For more, see Transaction Types
- Specify a table generation strategy for your database.
- 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