java-Hibernate的泛型
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-Hibernate的泛型,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1977字,纯文字阅读大概需要3分钟。
内容图文
![java-Hibernate的泛型](/upload/InfoBanner/zyjiaocheng/683/78978b048fc940e78907cae5927f4db1.jpg)
后续课程无法使用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扩展了Sample Class.
希望对您有所帮助.
注意:据我所知,它不能像您期望的那样通用.您不能提供任何对象作为参数.但是对象应该与您要定义的实体(如父级或子级)相关.这就是它在Hibernate中的工作方式.
内容总结
以上是互联网集市为您收集整理的java-Hibernate的泛型全部内容,希望文章能够帮你解决java-Hibernate的泛型所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】