我有三个模型,即UserAccount,CompanyMst和Property Master。
我能够将数据插入所有这些数据,但是在将列表作为JSon对象检索时,我得到以下错误。
模型如下。
@Entity
public class UserAccount extends Model {
@Id
public Long id;
@Constraints.Email
public String email = "";
public String password = "";
public String firstname = "";
public String lastname = "";
public String telno = "";
public String activationbytecode = "";
public String authtoken;
public String createToken() {
authtoken = UUID.randomUUID().toString();
save();
return authtoken;
}
public void deleteAuthToken() {
authtoken = null;
save();
}
@Formats.DateTime(pattern = "yyyy-MM-dd hh:mm:ss")
public Date createdOn = new Date();
@ManyToOne
public UserAccount createdby;
@Formats.DateTime(pattern = "yyyy-MM-dd hh:mm:ss")
public Date activatedOn;
public boolean activationstatus = false;
public boolean accountstatus = false;
@ManyToOne
@Constraints.Required
@JsonBackReference
public CompanyMst company;
@ManyToOne
public Roles role;
@Formats.DateTime(pattern = "yyyy-MM-dd hh:mm:ss")
public Date updatedon;
@ManyToOne
public UserAccount updateby;
}
公司模型如下。
@Entity
public class CompanyMst extends Model {
@Id
public Long id;
@Constraints.Required
public String name;
@Constraints.Required
public Integer buildingmanaged;
public Boolean isactive = false;
@Constraints.Required
public String address;
@Constraints.Required
@Constraints.Email
public String email;
@Constraints.Required
public String telno;
@Formats.DateTime(pattern="yyyy-MM-dd hh:mm:ss")
public Date subscriptiondatefrom;
@Formats.DateTime(pattern="yyyy-MM-dd hh:mm:ss")
public Date subscriptiondateto;
public Boolean subscriptionisexpired = false;
@Formats.DateTime(pattern="yyyy-MM-dd hh:mm:ss")
public Date createdon = new Date();
@ManyToOne
public UserAccount createdbyuser;
@Formats.DateTime(pattern="yyyy-MM-dd hh:mm:ss")
public Date updatedon;
@ManyToOne
public UserAccount updateby;
public static Finder<Long,CompanyMst> find = new Finder <>(CompanyMst.class);
public static CompanyMst findByCompanyName(String name){
return find.query().where().eq("name",name).findOne();
}
public static int getCompanyCount() {
return find.query().where().eq("isactive",true).findCount();
}
}
虽然属性模型如下
@Entity
public class PropertyMst extends Model {
@Id
public Long id;
public String code = "";
public String propertyname = "";
public String description = "";
public Boolean isactive = true;
public String plotlandnumber = "";
public Boolean islettable = Boolean.TRUE;
public Boolean depositrequired = Boolean.TRUE;
@Constraints.Required
public Integer nooflettableunits;
public String address ="";
@ManyToOne
@JsonManagedReference
public CompanyMst companyMst;
@WhenCreated
@Formats.DateTime(pattern="yyyy-MM-dd hh:mm:ss")
public Date createdon = new Date();
// @WhoCreated
@ManyToOne
public UserAccount createdbyuser;
@Formats.DateTime(pattern="yyyy-MM-dd hh:mm:ss")
public Date updatedon;
// @WhoModified
@ManyToOne
public UserAccount updatedby;
public static Finder<Long,PropertyMst> find = new Finder <>(PropertyMst.class);
public static PropertyMst findByPropertyName(String propertyname){
return PropertyMst.find.query().where().eq("propertyname",propertyname).findOne();
}
public static List<PropertyMst> propertyMstList(){
return new ArrayList<>(PropertyMst.find.query().where().eq("isactive",true).findList());
}
public static Map<String, String> options(CompanyMst companyMst){
LinkedHashMap<String,String> options=new LinkedHashMap<String,String>();
for(PropertyMst c:PropertyMst.find.query().where()
.eq("isactive",true)
.eq("companyMst",companyMst)
.findList()){
options.put(c.id.toString(),c.propertyname);
}
return options;
}
public static int getTotalProperties(){
return PropertyMst.find.all().size();
}
public static int getCompanyProperties(CompanyMst companyMst){
return PropertyMst.find.query().where().eq("companyMst", companyMst).findCount();
}
public static PropertyMst getPropertyByCompany(CompanyMst companyMst){
return PropertyMst.find.query().where().eq("companyMst",companyMst).findOne();
}
public static List<PropertyMst> getPropertyByCompanyList(CompanyMst companyMst){
return PropertyMst.find.query().where().eq("companyMst",companyMst).findList();
}
}
不确定我为什么会收到此错误
直接自我引用导致循环(通过参考链: io.ebean.common.BeanList [0] - &GT; models.PropertyMst [&#34; companyMst&#34;] - &GT; models.CompanyMst [&#34; createdbyuser&#34;] - &GT; models.UserAccount [& #34;由&#34;]创建,位于play.libs.Json.toJson
答案 0 :(得分:0)
添加用户模型
@JsonBackReference
@ManyToOne
public UserAccount createdby;