作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
以下类无法使用 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
请帮帮我。
最佳答案
你应该尝试类似的东西 -
@ManyToOne(targetEntity=Sample.class)
@JoinColumn(name = "<ID>")
private P parent;
@OneToMany(mappedBy = "parent", cascade = CascadeType.PERSIST, targetEntity=Sample.class)
private List<C> children;
其中,P 和 C 扩展了样本类。
希望对你有帮助。
注意:据我所知,它不能像您期望的那样通用。您不能提供任何对象作为参数。但是该对象应该与您定义的实体相关,例如 Parent 或 Child。这就是它在 Hibernate 中的工作方式。
关于java - Hibernate 泛型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35937644/
我是一名优秀的程序员,十分优秀!