在我为学习 CouchDB/Ektorp 而创建的一个小型 JSF 项目中,我遇到了 DocumentReferences 错误。我相信一切都在 CRUD 中按原样工作,父文档的 id 存储为字符串,类似于教程项目。但是当我从数据库中检索父对象时,我得到了这个错误:
org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type
[simple type, class com.pro.documents.Apple] from JSON String; no single-String
constructor/factory method (through reference chain: com.pro.documents.Eiere["apple"])
这是其余的代码:
{
"_id": "_design/Eiere",
"_rev": "17-ebb06b0d3102622a3d9849b9399cd94f",
"language": "javascript",
"views": {
"all": {
"map": "function(doc){if (doc.type == 'eiere') {emit(doc._id, doc);}}"
},
"ektorp_docrefs_apple": {
"map": "function(doc){ if(doc.eiere){emit([doc.eiere, 'apple', doc.kategori], null);}}"
}
}
}
{
"_id": "_design/Apple",
"_rev": "8-e04d8b5633776545b9eacdc998db4aea",
"language": "javascript",
"views": {
"all": {
"map": "function(doc){ if(doc.type == 'apple'){emit(doc._id, doc);}}"
}
}
}
public class Eiere extends CouchDbDocument {
@TypeDiscriminator
private String type;
private String navn;
private String telefon;
@DocumentReferences(backReference = "eiere", fetch = FetchType.LAZY, descendingSortOrder = true)
private Set<Apple> apple;
private Date dateCreated;
public Set<Apple> getApple() {
return apple;
}
public void setApple(Set<Apple> apples) {
this.apple = apples;
}
public void addApple(Apple c) {
Assert.notNull(c, "Apple may not be null");
if (getApple() == null) {
apple = new TreeSet<Apple>();
}
c.setEiere(this.getId());
apple.add(c);
}
public String getType() {
if (type == null) {
type = "eiere";
}
return type;
}
public void setType(String type) {
this.type = type;
}
public String getNavn() {
return navn;
}
public void setNavn(String navn) {
this.navn = navn;
}
public String getTelefon() {
return telefon;
}
public void setTelefon(String telefon) {
this.telefon = telefon;
}
public Date getDateCreated() {
return dateCreated;
}
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
}
public class Apple extends CouchDbDocument implements Comparable<Apple>{
private static final long serialVersionUID = 1L;
@TypeDiscriminator
private String type;
private List<String> prices;
private String kategori;
private String eiere;
private Date dateCreated;
public String getType() {
if(type == null){
type = "apple";
}
return type;
}
public void setType(String type) {
this.type = type;
}
public List<String> getPrices() {
if(prices == null){
prices = new ArrayList<String>();
prices.add(0, " ");
prices.add(1, " ");
prices.add(2, " ");
}
return prices;
}
public void setPrices(List<String> prices) {
this.prices = prices;
}
public String getKategori() {
return kategori;
}
public void setKategori(String kategori) {
this.kategori = kategori;
}
public String getEiere() {
return eiere;
}
public void setEiere(String eiere) {
this.eiere = eiere;
}
@Override
public String toString() {
return prices.toString();
}
public Date getDateCreated() {
return dateCreated;
}
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
@Override
public int compareTo(Apple other) {
if (other == this) return 0;
if (dateCreated != null) {
return - dateCreated.compareTo(other.dateCreated);
}
return 0;
}
}
任何帮助我理解我做错了什么的帮助或建议将不胜感激。
编辑:如果有任何我可以添加的信息可以使我的问题更清楚或有助于确定问题的原因,请告诉我。
兄弟。