gpt4 book ai didi

java - JPA错误: without eclipselink

转载 作者:行者123 更新时间:2023-12-02 04:29:27 24 4
gpt4 key购买 nike

我正在开发一个概念验证,其中我在动态 Web 项目中创建 JPA 实体并使用 servlet 来检索信息。我正在 SAP NW Java AS 中部署此应用程序。请忽略下面代码片段中的名称 odata,因为它与 odata 无关。

我收到以下错误:

WebServletException: Web container failed to find a resource neededfor injection, the following class [com.EXIDVPServFactory] cannot beput 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.**

我的 persistence.xml 看起来像:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="XXXXXXX" xmlns:xsi="XXXXXX" xsi:schemaLocation="XXXXXXXX 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>

我正在使用的 servlet 是:

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(实体对象)

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;
}





}

我创建了一个简单的 HTML 页面,它将向 servlet 发送一个 aufnr id 作为参数。请帮我解决这个问题。

最佳答案

将这些行添加到 persistence.xml 中:

<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>

希望有帮助。 eclipse.ddl- Generation 的其他选项可以在 here 中找到。 .

关于java - JPA错误: without eclipselink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31650045/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com