Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在JPA编程模型中使用继承?_Jpa_Eclipselink - Fatal编程技术网

如何在JPA编程模型中使用继承?

如何在JPA编程模型中使用继承?,jpa,eclipselink,Jpa,Eclipselink,我试图用JPA2.1实现这个模型。我正在使用JSR338规范和参考实现Eclipselink 只有第三级和关联类的实体将被持久化。 持久化的实体 public class FornecedorPecas extends FornecedorSuper { private Double Valor; @Column(name="ValorPeca") public Double getValor() { return Valor; } public void setValor(Do

我试图用JPA2.1实现这个模型。我正在使用JSR338规范和参考实现Eclipselink

只有第三级和关联类的实体将被持久化。

持久化的实体

public class FornecedorPecas extends FornecedorSuper {

private Double Valor;

@Column(name="ValorPeca")
public Double getValor() {
    return Valor;
}

public void setValor(Double valor) {
    Valor = valor;
}
}
有必要将FornecedorPeç标记为带有@Entity的类

当我在FornecedorSuper中插入mapped超类时。将引发此异常:

Exception in thread "main" Local Exception Stack: Exception [EclipseLink-30005] (Eclipse Persistence Services - .5.0.v20130507-3faac2b):org.eclipse.persistence.exceptions.PersistenceUnitLoadingException Exception Description: An exception was thrown while searching for persistence archives ith ClassLoader: sun.misc.Launcher$AppClassLoader@affc70 Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [modelo] failed.
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class br.miltex.dominio.model.FornecedorPecas] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
Q1。我可以在这里使用MappedSuperclass代替继承吗

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)    
public abstract class FornecedorSuper extends PessoaMaster{

    //attributes and relationships

}
虽然我在规范中没有找到任何这样的例子,但JPA规范说:

MappedSuperclass注释指定一个类,该类的映射 信息将应用于从中继承的实体。地图 超类没有为其定义单独的表

所以它说映射信息应用于实体,但它没有说不允许一个
MappedSuperclass
扩展另一个
MappedSuperclass
,所以我相信您可以在
FornecedorSuper
类中使用
@MappedSuperclass
注释

Q2.有必要将FornecedorPeç标记为带有@Entity的类吗


是的,这是必要的。

我已经在属性和方法上添加了注释。由于这个原因,出现了一些例外情况


谢谢您的帮助。

嗨,Andrei。上面的异常被抛出。谢谢!安德烈,他的回答并没有解决我的问题。每个人都可以自由访问该规范。你引用的话我已经读过了。他的回答是帮助。所以我把它标记为有用的。谢谢,安德烈,因为你删除了之前的评论?
Exception in thread "main" Local Exception Stack: Exception [EclipseLink-30005] (Eclipse Persistence Services - .5.0.v20130507-3faac2b):org.eclipse.persistence.exceptions.PersistenceUnitLoadingException Exception Description: An exception was thrown while searching for persistence archives ith ClassLoader: sun.misc.Launcher$AppClassLoader@affc70 Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [modelo] failed.
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class br.miltex.dominio.model.FornecedorPecas] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.