{OLINGO-618] Enhance Reference model

Signed-off-by: Chandan V A <chandan.v.a@sap.com>
diff --git a/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/factory/JPAEntityManagerFactory.java b/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/factory/JPAEntityManagerFactory.java
new file mode 100644
index 0000000..efc854d
--- /dev/null
+++ b/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/factory/JPAEntityManagerFactory.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.jpa.ref.factory;
+
+import java.util.HashMap;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+public class JPAEntityManagerFactory {
+  private static HashMap<String, EntityManagerFactory> emfMap;
+
+  public static EntityManagerFactory getEntityManagerFactory(final String pUnit) {
+    if (pUnit == null) {
+      return null;
+    }
+    if (emfMap == null) {
+      emfMap = new HashMap<String, EntityManagerFactory>();
+    }
+
+    if (emfMap.containsKey(pUnit)) {
+      return emfMap.get(pUnit);
+    } else {
+      EntityManagerFactory emf = Persistence.createEntityManagerFactory(pUnit);
+      emfMap.put(pUnit, emf);
+      return emf;
+    }
+
+  }
+}
\ No newline at end of file
diff --git a/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/LineItem.java b/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/LineItem.java
index bd162a5..d879471 100644
--- a/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/LineItem.java
+++ b/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/LineItem.java
@@ -20,10 +20,12 @@
 
 import javax.persistence.Column;
 import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
 import javax.persistence.JoinColumn;
 import javax.persistence.JoinColumns;
 import javax.persistence.ManyToOne;
 import javax.persistence.OneToOne;
+import javax.persistence.Table;
 import javax.validation.constraints.Digits;
 
 /**
@@ -34,6 +36,8 @@
  * <li>1..1 unidirectional relationship with "JoinColumns" annotation</li>
  * </ol>
  */
+@Entity
+@Table(name = "T_LINEITEM")
 public class LineItem {
   @EmbeddedId
   private LineItemKey key;
@@ -43,12 +47,12 @@
   private float netAmount;
 
   private Currency currency;
-  
+
   @Column(name = "QUANTITY")
   private int quantity;
 
   @ManyToOne
-  @JoinColumn(name = "SO_ID", referencedColumnName = "ID")
+  @JoinColumn(name = "SO_ID", referencedColumnName = "ID", insertable = false, updatable = false)
   private SalesOrder order;
 
   @Column(name = "DELIVERED")
diff --git a/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/Product.java b/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/Product.java
index a8e08ec..f8766ef 100644
--- a/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/Product.java
+++ b/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/Product.java
@@ -18,12 +18,14 @@
  ******************************************************************************/
 package org.apache.olingo.jpa.ref.model;
 
-import java.sql.Date;
+import java.util.Date;
 import java.util.Set;
 
 import javax.persistence.Column;
+import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.ManyToMany;
+import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 
@@ -34,6 +36,8 @@
  * <li>M..N bidirectional relationship</li>
  * </ol>
  */
+@Entity
+@Table(name = "T_PRODUCT")
 public class Product {
 
   @Id
diff --git a/ext/odata-jpa/odata-jpa-ref-persistence/src/main/resources/META-INF/persistence.xml b/ext/odata-jpa/odata-jpa-ref-persistence/src/main/resources/META-INF/persistence.xml
index 66ab54b..b7d4089 100644
--- a/ext/odata-jpa/odata-jpa-ref-persistence/src/main/resources/META-INF/persistence.xml
+++ b/ext/odata-jpa/odata-jpa-ref-persistence/src/main/resources/META-INF/persistence.xml
@@ -16,6 +16,13 @@
 		transaction-type="RESOURCE_LOCAL">
 		<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 		<class>org.apache.olingo.jpa.ref.model.Customer</class>
+		<class>org.apache.olingo.jpa.ref.model.BusinessPartner</class>
+		<class>org.apache.olingo.jpa.ref.model.Address</class>
+		<class>org.apache.olingo.jpa.ref.model.Employee</class>
+		<class>org.apache.olingo.jpa.ref.model.LineItem</class>
+		<class>org.apache.olingo.jpa.ref.model.Product</class>
+		<class>org.apache.olingo.jpa.ref.model.SalesOrder</class>
+		<class>org.apache.olingo.jpa.ref.model.Supplier</class>
 		<properties>
 			<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
 			<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:apache.olingo.jpa.sample" />
diff --git a/ext/odata-jpa/odata-jpa-ref-web/pom.xml b/ext/odata-jpa/odata-jpa-ref-web/pom.xml
index 9e0c3d5..99268d1 100644
--- a/ext/odata-jpa/odata-jpa-ref-web/pom.xml
+++ b/ext/odata-jpa/odata-jpa-ref-web/pom.xml
@@ -38,6 +38,27 @@
 			<artifactId>odata-jpa-core</artifactId>
 			<version>${project.version}</version>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.olingo</groupId>
+			<artifactId>odata-jpa-ref-persistence</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.olingo</groupId>
+			<artifactId>odata-server-api</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.olingo</groupId>
+			<artifactId>odata-server-core</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.olingo</groupId>
+			<artifactId>odata-commons-api</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.olingo</groupId>
+			<artifactId>odata-commons-core</artifactId>
+		</dependency>
 	</dependencies>
 	<build>
 		<finalName>odata-jpa-ref-web</finalName>
diff --git a/ext/odata-jpa/odata-jpa-ref-web/src/main/java/org/apache/olingo/jpa/ref/web/servlet/SalesOrderProcessingServlet.java b/ext/odata-jpa/odata-jpa-ref-web/src/main/java/org/apache/olingo/jpa/ref/web/servlet/SalesOrderProcessingServlet.java
index 8e69b92..4065790 100644
--- a/ext/odata-jpa/odata-jpa-ref-web/src/main/java/org/apache/olingo/jpa/ref/web/servlet/SalesOrderProcessingServlet.java
+++ b/ext/odata-jpa/odata-jpa-ref-web/src/main/java/org/apache/olingo/jpa/ref/web/servlet/SalesOrderProcessingServlet.java
@@ -1,9 +1,8 @@
 package org.apache.olingo.jpa.ref.web.servlet;
 
 import org.apache.olingo.jpa.api.ODataJPAContext;
-import org.apache.olingo.jpa.api.ODataJPAService;
 import org.apache.olingo.jpa.api.ODataJPAServlet;
-import org.apache.olingo.jpa.api.factory.ODataJPAFactory;
+import org.apache.olingo.jpa.ref.factory.JPAEntityManagerFactory;
 
 public class SalesOrderProcessingServlet extends ODataJPAServlet {
 
@@ -11,12 +10,11 @@
    * 
    */
   private static final long serialVersionUID = 1L;
-  private ODataJPAService odataJPAService = null;
-  private ODataJPAContext odataJPAContext = null;
 
   @Override
   protected void initializeODataJPAContext(ODataJPAContext odataJPAContext) {
-    odataJPAContext.setPersistenceUnitName();
+    odataJPAContext.setPersistenceUnitName(getPersistenceUnitName());
+    odataJPAContext.setEntityManagerFactory(JPAEntityManagerFactory.getEntityManagerFactory(getPersistenceUnitName()));
   }
 
 }
diff --git a/ext/odata-jpa/pom.xml b/ext/odata-jpa/pom.xml
index 1640cf0..500d951 100644
--- a/ext/odata-jpa/pom.xml
+++ b/ext/odata-jpa/pom.xml
@@ -69,9 +69,19 @@
 			</dependency>
 			<dependency>
 				<groupId>org.apache.olingo</groupId>
+				<artifactId>odata-server-core</artifactId>
+				<version>${version.odata}</version>
+			</dependency>
+			<dependency>
+				<groupId>org.apache.olingo</groupId>
 				<artifactId>odata-commons-api</artifactId>
 				<version>${version.odata}</version>
 			</dependency>
+			<dependency>
+				<groupId>org.apache.olingo</groupId>
+				<artifactId>odata-commons-core</artifactId>
+				<version>${version.odata}</version>
+			</dependency>
 		</dependencies>
 	</dependencyManagement>
 </project>
\ No newline at end of file