Java 使用Odata服务的SAP UI5应用程序:对象不是声明类的实例
我已经创建了一个odata服务 当我访问上面的URL时,它会正确地显示实体集Java 使用Odata服务的SAP UI5应用程序:对象不是声明类的实例,java,odata,Java,Odata,我已经创建了一个odata服务 当我访问上面的URL时,它会正确地显示实体集 <service xmlns="<LINK>2007/app" xmlns:atom="<LINK>2005/Atom" xml:base="<SAME URL AS ABOVE>carandodatabaseodata/emplist.svc/"> <workspace> <atom:title>Default</atom:ti
<service xmlns="<LINK>2007/app" xmlns:atom="<LINK>2005/Atom" xml:base="<SAME URL AS ABOVE>carandodatabaseodata/emplist.svc/">
<workspace>
<atom:title>Default</atom:title>
<collection href="ZaeScaleprinters">
<atom:title>ZaeScaleprinters</atom:title>
</collection>
</workspace>
</service>
实体类:
package model;
import java.io.Serializable;
import javax.persistence.*;
/**
* The persistent class for the ZAE_SCALEPRINTER database table.
*
*/
@Entity
@Table(name="ZAE_SCALEPRINTER")
public class ZaeScaleprinter implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private ZaeScaleprinterPK id;
public ZaeScaleprinter() {
}
public ZaeScaleprinterPK getId() {
return this.id;
}
public void setId(ZaeScaleprinterPK id) {
this.id = id;
}
}
package model;
import java.io.Serializable;
import javax.persistence.*;
/**
* The primary key class for the ZAE_SCALEPRINTER database table.
*
*/
@Embeddable
public class ZaeScaleprinterPK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
@Column(unique=true, nullable=false, length=12)
private String werks;
@Column(unique=true, nullable=false, length=60)
private String scale;
@Column(unique=true, nullable=false, length=120)
private String printer;
public ZaeScaleprinterPK() {
}
public String getWerks() {
return this.werks;
}
public void setWerks(String werks) {
this.werks = werks;
}
public String getScale() {
return this.scale;
}
public void setScale(String scale) {
this.scale = scale;
}
public String getPrinter() {
return this.printer;
}
public void setPrinter(String printer) {
this.printer = printer;
}
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof ZaeScaleprinterPK)) {
return false;
}
ZaeScaleprinterPK castOther = (ZaeScaleprinterPK)other;
return
this.werks.equals(castOther.werks)
&& this.scale.equals(castOther.scale)
&& this.printer.equals(castOther.printer);
}
public int hashCode() {
final int prime = 31;
int hash = 17;
hash = hash * prime + this.werks.hashCode();
hash = hash * prime + this.scale.hashCode();
hash = hash * prime + this.printer.hashCode();
return hash;
}
}
你的类中有继承吗?我认为可能实体集中有一个派生类型的对象,而派生类型未包含/定义在Edm模型中。也许你最好能和我们分享你的元数据文档和实体集对象。我已经在上面添加了元数据信息。我没有创建任何类。我使用EclipseJuno向导构建了一个应用程序Odata-Starter应用程序Projectt的行为有所不同。现在它给了我一个错误:sun.reflect.DelegatingMethodAccessorImpl:java.lang。ClassCastException@3c4928. 现在又是先前的错误。。。!也许您应该将java添加到标记中。在我看来,这个问题不像UI5客户端问题,而是服务器端问题。
<error xmlns="<LINK>/ado/2007/08/dataservices/metadata">
<code/>
<message xml:lang="en">
"sun.reflect.NativeMethodAccessorImpl: object is not an instance of declaring class. "
</message>
</error>
package com;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
import org.apache.olingo.odata2.processor.api.jpa.ODataJPAServiceFactory;
import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
public class ZAE_SCALEPrinterServiceFactory extends ODataJPAServiceFactory {
private static final String PERSISTENCE_UNIT_NAME = "carandodatabaseodata";
@Override
public ODataJPAContext initializeODataJPAContext()
throws ODataJPARuntimeException {
ODataJPAContext oDatJPAContext = this.getODataJPAContext();
try {
EntityManagerFactory emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
oDatJPAContext.setEntityManagerFactory(emf);
oDatJPAContext.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
return oDatJPAContext;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
package model;
import java.io.Serializable;
import javax.persistence.*;
/**
* The persistent class for the ZAE_SCALEPRINTER database table.
*
*/
@Entity
@Table(name="ZAE_SCALEPRINTER")
public class ZaeScaleprinter implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private ZaeScaleprinterPK id;
public ZaeScaleprinter() {
}
public ZaeScaleprinterPK getId() {
return this.id;
}
public void setId(ZaeScaleprinterPK id) {
this.id = id;
}
}
package model;
import java.io.Serializable;
import javax.persistence.*;
/**
* The primary key class for the ZAE_SCALEPRINTER database table.
*
*/
@Embeddable
public class ZaeScaleprinterPK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
@Column(unique=true, nullable=false, length=12)
private String werks;
@Column(unique=true, nullable=false, length=60)
private String scale;
@Column(unique=true, nullable=false, length=120)
private String printer;
public ZaeScaleprinterPK() {
}
public String getWerks() {
return this.werks;
}
public void setWerks(String werks) {
this.werks = werks;
}
public String getScale() {
return this.scale;
}
public void setScale(String scale) {
this.scale = scale;
}
public String getPrinter() {
return this.printer;
}
public void setPrinter(String printer) {
this.printer = printer;
}
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof ZaeScaleprinterPK)) {
return false;
}
ZaeScaleprinterPK castOther = (ZaeScaleprinterPK)other;
return
this.werks.equals(castOther.werks)
&& this.scale.equals(castOther.scale)
&& this.printer.equals(castOther.printer);
}
public int hashCode() {
final int prime = 31;
int hash = 17;
hash = hash * prime + this.werks.hashCode();
hash = hash * prime + this.scale.hashCode();
hash = hash * prime + this.printer.hashCode();
return hash;
}
}