Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

JPA error

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.

Former Member
replied

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?

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question