on 07-27-2015 10:41 AM
Hello Experts,
I am developing a proof of concept wherein I am creating JPA entities in Dynamic web project and using a servlet to retrieve information.
Please ignore the name odata in below code snippets as ithis has nothing to do with odata.
I am getting below error :
WebServletException: Web container failed to find a resource needed for injection, the following class [com.EXIDVPServFactory] cannot be put into service.
Caused by: java.lang.RuntimeException: The persistence unit is inconsistent with the database schema:
Error on entity >>model.ZaeExidvp<<: The table >>ZAE_EXIDVP<< does not exist.
My persistence.xml looks like :
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
<persistence-unit name="basicodata" transaction-type="RESOURCE_LOCAL">
<provider>javax.persistence.PersistenceProvider</provider>
<class>model.ZaeExidvp</class>
<class>model.ZaeExidvpPK</class>
<properties>
<property name="javax.persistence.jdbc.url" value="XXXXXXXXXXXX"/>
<property name="javax.persistence.jdbc.user" value="sapsr3db"/>
<property name="javax.persistence.jdbc.password" value="XXXXXX"/>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
</properties>
</persistence-unit>
</persistence>
The servlet that I am using is :
package com;
import java.io.IOException;
import model.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.persistence.*;
/**
* Servlet implementation class EXIDVPServFactory
*/
public class EXIDVPServFactory extends HttpServlet {
//@PersistenceUnit (unitName = "basicodata")
private static final String PERSISTENCE_UNIT_NAME = "basicodata";
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public EXIDVPServFactory() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//EntityManager em = emf.createEntityManager();
EntityManagerFactory emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = emf.createEntityManager();
// ODataJPAContext oDatJPAContext = this.getODataJPAContext();
String aufnr = request.getParameter("aufnr");
ZaeExidvp exidvp = em.find(ZaeExidvp.class, aufnr);
response.getOutputStream().print(exidvp.getId().toString());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
CLASS ZAE_EXIDVP (Entity object)
package model;
import java.io.Serializable;
import javax.persistence.*;
import java.sql.Timestamp;
/**
* The persistent class for the ZAE_EXIDVP database table.
*
*/
@Entity
@Table(name="ZAE_EXIDVP")
public class ZaeExidvp implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private ZaeExidvpPK id;
public ZaeExidvp() {
}
public ZaeExidvpPK getId() {
return this.id;
}
public void setId(ZaeExidvpPK id) {
this.id = id;
}
}
I have created a simple HTML page that will send one aufnr id as parameter to servlet.
Please assist me in resolving this.
Well, the error says it all Your table ZAE_EXIDVP does not yet exist. Can you check if it exists, and you are connecting to the correct tablespace?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Robin,
You were correct.
Actually I am using my internal SAP server.
And database exist on my client network.
Earlier I was having server on my own machine where VPN to client network was already connected, so things worked fine.
But now since we are using our internal NW server that exist on another machine, terefore I had to connect VPN on server.
SO that error is gone.
Now I am facing next stage challenge.
I hope you will not mind in having a look
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.