当我试图将一个实体映射到多个实体时,我得到了这个错误。
///这是我的候选人配置文件实体//////////
package com.demo.project.premiumjobportal.model; import java.io.Serializable; 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.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.validation.constraints.NotNull; import javax.xml.bind.annotation.XmlRootElement; import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; //Candidate details table : Master Table @Entity @Table(name="candidate_profile") @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) @XmlRootElement public class CandidateProfile implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue private int id; @NotNull @Column(name="first_name", length = 25) private String firstName; @NotNull @Column(name="last_name", length = 25) private String lastName; @NotNull @Column(name="username", length = 50) private String username; @Column(name="alt_email_id", length = 50) private String alternateEmailId; @NotNull @Column(name="mobile_no", length = 15) private String mobileNum; @Column(name="alt_mobile_no", length = 15) private String alternateMobileNum; @Column(name="ssc_board", length = 50) private String sscBoard; @Column(name="ssc_school", length = 50) private String sscSchool; @Column(name="ssc_percent", length = 4) private float sscPercentage; @Column(name="ssc_year_of_passout", length = 4) private int sscYearOfPassout; @Column(name="hsc_board", length = 50) private String hscBoard; @Column(name="hsc_school", length = 50) private String hscSchool; @Column(name="hsc_percent", length = 4) private float hscPercentage; @Column(name="hsc_year_of_passout", length = 4) private int hscYearOfPassout; @Column(name="grad_university", length = 100) private String gradiduteUniversity; @Column(name="grad_institute", length = 100) private String gradiduteInstitute; @Column(name="grad_percent", length = 4) private float gradidutePercentage; @Column(name="grad_year_of_passout", length = 4) private int gradiduteYearOfPassout; @Column(name="postgrad_university", length = 100) private String postGradiduteUniversity; @Column(name="postgrad_institute", length = 100) private String postGradiduteInstitute; @Column(name="postgrad_percent", length = 4) private float postGradidutePercentage; @Column(name="postgrad_year_of_passout", length = 4) private int postGradiduteYearOfPassout; private String notes; private String Password; @OneToMany(mappedBy = "candidateProfile", fetch = FetchType.LAZY,cascade = CascadeType.REMOVE) @JsonBackReference private List experienceDetails; @OneToMany(mappedBy = "candidateProfile", fetch = FetchType.LAZY,cascade = CascadeType.REMOVE) @JsonBackReference private List candidateJobs; @ManyToOne private Role roleName; /* Constructor */ public CandidateProfile() { super(); } // Getters and Setters
///这是我的体验详情实体//////////////
package com.cfa.project.premiumjobportal.model; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.xml.bind.annotation.XmlRootElement; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; //Experience class, which connected with CandidateProfile.class @Entity @Table(name="experience_details") @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) @XmlRootElement public class ExperienceDetails implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue private int id; @Column(name = "tot_experenice", length = 2) private String totExperience; @Column(name = "companies_month_experience") private String companiesMonthExperience; @Column(name = "skills") private String _skills; @Column(name = "extra_curricular") private String extraCurricular; private String notes; /* Mapping : Joining with Candidate table */ @ManyToOne private CandidateProfile candidateProfile; /*Constructor*/ public ExperienceDetails() { super(); } /*Constructor using fields*/ /** * @param id * @param totExperience * @param companiesMonthExperience * @param _skills * @param extraCurricular * @param notes * @param candidateProfile */ public ExperienceDetails(int id, String totExperience, String companiesMonthExperience, String _skills, String extraCurricular, String notes, CandidateProfile candidateProfile) { super(); this.id = id; this.totExperience = totExperience; this.companiesMonthExperience = companiesMonthExperience; this._skills = _skills; this.extraCurricular = extraCurricular; this.notes = notes; this.candidateProfile = candidateProfile; } /* Generating Getters and setters */
///这是我的角色实体//////
import java.io.Serializable; 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.Id; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.xml.bind.annotation.XmlRootElement; import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @Entity @Table(name="role") @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) @XmlRootElement public class Role implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue private int id; @Column(length = 10) private String name; @OneToMany(mappedBy = "roleName", fetch = FetchType.LAZY,cascade = CascadeType.REMOVE) @JsonBackReference private List candidateProfiles; @OneToMany(mappedBy = "companyRoleName", fetch = FetchType.LAZY,cascade = CascadeType.REMOVE) @JsonBackReference private List recruiterDetails;
我得到的这个错误-----------
Failed to evaluate Jackson deserialization for type [[simple type, class
com.demo.project.premiumjobportal.model.CandidateProfile]]:
com.fasterxml.jackson.databind.JsonMappingException: Multiple back-reference
properties with name 'defaultReference'
请帮帮我。我到处搜索,我尝试了每一个解决方案,但我也得到了这个错误。
如果您在项目中对getter/setter方法使用@JsonBackReference两次以上,则应该使用特定的引用名称来区分它们。
在role
实体类中,您已经两次使用了@JsonBackReference
@OneToMany(mappedBy = "roleName", fetch = FetchType.LAZY,cascade = CascadeType.REMOVE)
@JsonBackReference
private List candidateProfiles;
@OneToMany(mappedBy = "companyRoleName", fetch = FetchType.LAZY,cascade = CascadeType.REMOVE)
@JsonBackReference
private List recruiterDetails;
你应该改成-
@OneToMany(mappedBy = "roleName", fetch = FetchType.LAZY,cascade = CascadeType.REMOVE)
@JsonBackReference(value="candidate-profiles")
private List candidateProfiles;
@OneToMany(mappedBy = "companyRoleName", fetch = FetchType.LAZY,cascade = CascadeType.REMOVE)
@JsonBackReference(value="recruiter-details")
private List recruiterDetails;
我试图使用Jackson 1.9将嵌套的JSON对象反序列化到POJO中,但遇到了麻烦。下面是我试图解析的类和示例JSON字符串。 (省略了getter和setter) JSON字符串: Java类: 但是,当我尝试执行反序列化时: 我收到以下异常消息: JAVAlang.IllegalArgumentException:名为“defaultReference”的多个反向引用属性 我读到提供(va
我在一个类中有多个反向引用类。由于我对它们使用了,所以我得到了一个错误。我为这些类分配了注释,但仍然得到相同的错误。 错误:
我试图将一个json(字符串格式)映射到一个对象,但我得到以下错误 JSONMappingException:多个名为“default reference”的反向引用属性 这是json字符串 我不知道这个错误,我做了完全相同的方式,我读杰克逊的主页。知道这件事的人请帮帮我
简单地说,我能够让Jackson2.1.2将类层次结构序列化为带有类型信息的JSON字符串。但是,我无法让Jackson2.1.2将JSON字符串反序列化回到我类层次结构中。下面是一个暴露这个问题的单元测试。 类层次结构足够简单;只有两个直接子类的基类。此外,JSON输出似乎尊重我的Jackson@JsonTypeInfo,并从Mapper.WriteValueString生成一个可信的字符串 但
问题内容: 我试图使用Spring Boot / Spring RestController后端从AngularJS前端发布到http:// localhost:9095 / translators 。 我可以执行GET,响应如下: 当我发布下面的json时,我得到了 错误 响应 发布数据: 错误: 我确保我的控制器具有正确的Mediatype批注。 经过一些研究并通过查看日志输出,我意识到这是一
问题内容: 我正在针对返回JSON数据的第三方API进行编程,但是格式可能有点奇怪。某些属性可以是一个对象(包含一个Id属性),也可以是一个字符串(它是该对象的ID)。例如,以下两个都是有效的: 和 我正在尝试使用JSON.net将其反序列化为强类型类,但到目前为止运气还不足。我最好的主意是将其序列化为两个属性,一个为字符串,另一个为对象,并为每个属性使用自定义JsonConverter以允许变量