CodesJava

Easy learning with example program codes

JPA Persistence Unit


A persistence unit defines a set of all user defined persistable classes that are managed by EntityManager instances in an application. This set of entity classes represents the data contained within a single data store. . A Persistence each in turn containing a number of properties and attributes. Persistence units are defined in the persistence.xml file.

persistence.xml:

The persistence.xml file have to be put under the META-INF directory in the classpath. The persistence.xml file can include definitions for one or more Persistence Units. The EntityManagerFactory will need Persistence name to refer the persistence-unit.

persistence.xml example:

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
 
   <persistence-unit name="my-pu">
     <description>Test Persistence Unit</description>
     <provider> org.eclipse.persistence.jpa.PersistenceProvider </provider>
     <mapping-file>META-INF/mappingFile.xml</mapping-file>
     <jar-file>test.jar</jar-file>
     <class>TestEntity1</class>
     <class>TestEntity2</class>
     <properties>
       <property name="propertyName" value="propertyValue"/>
     </properties>
   </persistence-unit>
 
</persistence>
Posted in JPA   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki