Hi ! Today we add producer class to our project. Lets start ! 🙂
- Create package „producer”. Right click on „java” folder, then select New -> Package.
- Inside package, create producer class named JavaJPAServiceFactory.
- Fill class by the code bellow.
123456789101112131415161718192021package producer;import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;import org.apache.olingo.odata2.jpa.processor.api.ODataJPAServiceFactory;import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;import org.apache.olingo.odata2.jpa.processor.ref.factory.JPAEntityManagerFactory;public class JavaJPAServiceFactory extends ODataJPAServiceFactory {private static final String PUNIT_NAME = "odataJPAService";@Overridepublic ODataJPAContext initializeODataJPAContext()throws ODataJPARuntimeException {ODataJPAContext oDataJPAContext = getODataJPAContext();oDataJPAContext.setEntityManagerFactory(JPAEntityManagerFactory.getEntityManagerFactory(PUNIT_NAME));oDataJPAContext.setPersistenceUnitName(PUNIT_NAME);return oDataJPAContext;}} - Create new package „resources” in main package.
- Inside package create persistence.xml file.
- Fill file by code bellow.
123456789101112131415161718192021222324<?xml version="1.0" encoding="UTF-8"?><persistence version="2.0"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_2_0.xsd"><persistence-unit name="odataJPAService"transaction-type="RESOURCE_LOCAL"><provider>org.hibernate.ejb.HibernatePersistence</provider><class>model.Address</class><class>model.Parcel</class><class>model.Warehouse</class><exclude-unlisted-classes>true</exclude-unlisted-classes><properties><property name="javax.persistence.jdbc.user" value=""/><property name="javax.persistence.jdbc.password" value=""/><property name="javax.persistence.jdbc.url" value=""/><property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/><property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/><property name="hibernate.max_fetch_depth" value="3"/><property name="hibernate.show_sql" value="true"/><property name="hibernate.format_sql" value="true"/></properties></persistence-unit></persistence> - Click on create JPA facet and add file to its configuration.
It’s all today. In next part we try to make annotations and run our project.