我有两个实体课程,praum和praumgruppe。 这个类是hibernate和java jackson mapper。
我在mvc中使用spring / jersey进行开发。
在课堂上,praum是使用班级praumgruppe。类praumgruppe还返回一个praum对象列表。
praumgruppe类的代码
(?!\.)
praum班的代码
(?<!\.)
来自PraumController方法的代码
package de.decon.flaeche.model;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonBackReference;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonManagedReference;
import org.codehaus.jackson.annotate.JsonProperty;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import de.decon.catalogs.model.DeconKatEintragModel;
import de.decon.catalogs.model.KatKostenstelleModel;
import de.decon.flaeche.model.interfaces.PraumgruppeModelInterface;
@Entity
@Table(name = "p_raumgruppe")
@Inheritance(strategy = InheritanceType.JOINED)
@JsonAutoDetect
@JsonIgnoreProperties(ignoreUnknown = true)
public class PraumgruppeModel implements PraumgruppeModelInterface {
@OneToMany(mappedBy = "praumgruppe", fetch = FetchType.LAZY, cascade = CascadeType.ALL, targetEntity = PraumModel.class)
@LazyCollection(LazyCollectionOption.EXTRA)
@Cascade({org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private List<PraumModel> listPraum = new ArrayList<PraumModel>();
@JsonManagedReference
public List<PraumModel> getListPraum() {
return listPraum;
}
public void setListPraum(List<PraumModel> listPraum) {
this.listPraum = listPraum;
}
}
在回复中始终缺少属性praumgruppe。
package de.decon.flaeche.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonBackReference;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import de.decon.catalogs.model.DeconKatEintragModel;
import de.decon.flaeche.model.interfaces.PraumModelInterface;
@Entity
@Table(name = "p_raum")
@Inheritance(strategy = InheritanceType.JOINED)
@JsonAutoDetect
@JsonIgnoreProperties(ignoreUnknown = true)
public class PraumModel implements PraumModelInterface {
@ManyToOne(targetEntity = PraumgruppeModel.class)
@JoinColumn(name = "id_praumgruppe")
private PraumgruppeModel praumgruppe;
@ManyToOne(targetEntity = PraumModel.class)
@JoinColumn(name = "id_p_raum")
private PraumModel parent;
/**
* Getter und Setter
*/
@JsonBackReference
@JsonProperty("praumgruppe")
@JsonIgnore(false)
public PraumgruppeModel getPraumgruppe() {
return praumgruppe;
}
public void setPraumgruppe(PraumgruppeModel praumgruppe) {
this.praumgruppe = praumgruppe;
}
@JsonProperty("parent")
public PraumModel getParent() {
return parent;
}
public void setParent(PraumModel parent) {
this.parent = parent;
}
}
有什么问题?
非常感谢你的帮助。