dsk*_*dsk 3 java hibernate jpa
以下类无法使用 Hibernate 加载
package com.project.alice.entities;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonProperty;
@Table
@Entity
public class AnyInformation<T, K> {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@JsonProperty("id")
private long id;
@JsonProperty("parent")
@ManyToOne
private T parent;
@ManyToOne
@JsonProperty("parentType")
private K parentType;
@JsonProperty("informationType")
private String informationType;
@JsonProperty("information")
private String information;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public T getParent() {
return parent;
}
public void setParent(T parent) {
this.parent = parent;
}
public K getParentType() {
return parentType;
}
public void setParentType(K parentType) {
this.parentType = parentType;
}
public String getInformationType() {
return informationType;
}
public void setInformationType(String informationType) {
this.informationType = informationType;
}
public String getInformation() {
return information;
}
public void setInformation(String information) {
this.information = information;
}
}
org.hibernate.AnnotationException:
Property com.project.alice.entities.AnyInformation.parent
has an unbound type and no explicit target entity.
Resolve this Generic usage issue or set an explicit target attribute
(eg @OneToMany(target=) or use an explicit @Type
Run Code Online (Sandbox Code Playgroud)
请在这里帮助我。
你应该尝试类似 -
@ManyToOne(targetEntity=Sample.class)
@JoinColumn(name = "<ID>")
private P parent;
@OneToMany(mappedBy = "parent", cascade = CascadeType.PERSIST, targetEntity=Sample.class)
private List<C> children;
Run Code Online (Sandbox Code Playgroud)
其中,P 和 C 扩展了 Sample Class。
我希望它有帮助。
注意:据我所知,它不能像您期望的那样通用。您不能提供任何对象作为参数。但是该对象应该与您定义的实体相关,例如 Parent 或 Child。这就是它在 Hibernate 中的工作方式。
| 归档时间: |
|
| 查看次数: |
5999 次 |
| 最近记录: |