Creating a Persistence Unit
See Also
A persistence unit is required if you are using Java Persistence in your project.
To create a persistence unit:
- In the Projects window, right-click the 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 dropdown list, or add a new library by choosing New Persistence Library.
- Select a data source from the dropdown list.
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 container.
If you are not deploying to a Java EE 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 EJB and WAR projects, 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 archive or the
WEB-INF/classes directory of a WAR archive.
- See Also
- Working with Enterprise Applications
- About Persistence Units
Legal Notices