Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将DocumentReferences与Ektorp和JSF一起使用时出错_Java_Jsf 2_Couchdb_Jackson_Ektorp - Fatal编程技术网

Java 将DocumentReferences与Ektorp和JSF一起使用时出错

Java 将DocumentReferences与Ektorp和JSF一起使用时出错,java,jsf-2,couchdb,jackson,ektorp,Java,Jsf 2,Couchdb,Jackson,Ektorp,在我为学习CouchDB/Ektorp而创建的一个小型JSF项目中,文档引用出现了一个错误。 我相信在CRUD中一切都正常工作,父文档的id存储为字符串,类似于教程项目。 但是,当我从数据库检索父对象时,会出现以下错误: org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type [simple type, class com.pro.documents.Apple] from JSON St

在我为学习CouchDB/Ektorp而创建的一个小型JSF项目中,文档引用出现了一个错误。 我相信在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;
    }
}
任何帮助我理解我做错了什么的建议都将不胜感激

编辑:如果有任何信息,我可以添加,这将使我的问题更清楚或有助于确定它的原因,请让我知道


比尔

只是猜测一下,将空构造函数添加到Apple类中只是添加空构造函数会产生相同的错误。添加一个接受字符串参数的对象,删除错误并显示列表,但我没有得到任何apple对象。