2016-09-20 6 views
0

このエラーが発生したにもかかわらず、問題を解決する方法がわかりません。私はこの問題はmappedByことができることを読んだことがあるので、私は別の選択肢を試すが、問題がmappedByリファレンス不明なターゲットエンティティプロパティ - 休止状態のエラーManytoMany

コンソール持続:

Exception in thread "main" org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: oodb.Model.articles in oodb.Article.models 
    at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:775) 
    at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:725) 
    at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:54) 
    at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1621) 
    at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1589) 
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:278) 
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83) 
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418) 
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87) 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691) 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726) 
    at testoodb.CreaArticolo.main(CreaArticolo.java:20) 

Model.java:

package oodb; 

import static javax.persistence.GenerationType.IDENTITY; 

import java.util.HashSet; 
import java.util.Set; 

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.JoinColumn; 
import javax.persistence.JoinTable; 
import javax.persistence.ManyToMany; 
import javax.persistence.Table; 
import javax.persistence.UniqueConstraint; 



@Entity 
@Table(name = "model", catalog = "oogvg", uniqueConstraints = { 
     @UniqueConstraint(columnNames = "code")}) 
public class Model { 
    private Integer ModelId; 
    private String code; 
    private String description; 
    private Double cost; 
    private Double price; //selling price 
    private Set<Article> articles= new HashSet<Article>(0); // lista di articoli 

    public Model(){}; 

    public Model(String code, String description, Double cost, Double price) { 
     super(); 
     this.code = code; 
     this.description = description; 
     this.cost = cost; 
     this.price = price; 
    } 

    @Id 
    @GeneratedValue(strategy = IDENTITY) 
    @Column(name = "model_id", unique = true, nullable = false) 
    public Integer getModelId() { 
     return ModelId; 
    } 

    public void setModelId(Integer modelId) { 
     ModelId = modelId; 
    } 

    @Column(name = "code", unique = true, nullable = false, length = 10) 
    public String getCode() { 
     return code; 
    } 

    public void setCode(String code) { 
     this.code = code; 
    } 

    @Column(name = "description") 
    public String getDescription() { 
     return description; 
    } 

    public void setDescription(String description) { 
     this.description = description; 
    } 

    @Column(name = "cost") 
    public Double getCost() { 
     return cost; 
    } 

    public void setCost(Double cost) { 
     this.cost = cost; 
    } 

    @Column(name = "price") 
    public Double getPrice() { 
     return price; 
    } 

    public void setPrice(Double price) { 
     this.price = price; 
    } 


    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) 
    @JoinTable(name = "model_article", catalog = "oogvg", joinColumns = { 
      @JoinColumn(name = "model_id", nullable = false, updatable = false) }, 
      inverseJoinColumns = { @JoinColumn(name = "article_id", 
        nullable = false, updatable = false) }) 
    public Set<Article> getArticle() { 
     return articles; 
    } 

    public void setArticle(Set<Article> article) { 
     this.articles = article; 
    } 

    @Override 
    public String toString() { 
     return "Model [ModelId=" + ModelId + ", code=" + code + ", description=" + description + ", cost=" + cost 
       + ", price=" + price + "]"; 
    } 




} 

Article.java

package oodb; 

import static javax.persistence.GenerationType.IDENTITY; 

import java.util.HashSet; 
import java.util.Set; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.FetchType; 
import javax.persistence.GeneratedValue; 
import javax.persistence.Id; 
import javax.persistence.ManyToMany; 
import javax.persistence.Table; 


@Entity 
@Table(name = "article", catalog = "oogvg") 
public class Article { 
    private Integer id; 
    private String ean; 
    private Integer quantity; 
    private String color; // stringa exa 
    private String size; 
    private Integer pos; 
    private Set<Model> models= new HashSet<Model>(0); 

    public Article(){}; 

    public Article(String ean, Integer quantity, String color, String size, Integer pos) { 
     super(); 
     this.ean = ean; 
     this.quantity = quantity; 
     this.color = color; 
     this.size = size; 
     this.pos = pos; 

    } 


    public Article(String ean, Integer quantity, String color, String size, Integer pos, Set<Model> models) { 
     super(); 
     this.ean = ean; 
     this.quantity = quantity; 
     this.color = color; 
     this.size = size; 
     this.pos = pos; 
     this.models = models; 
    } 




    @Id 
    @GeneratedValue(strategy = IDENTITY) 
    @Column(name = "article_id", unique = true, nullable = false) 
    public Integer getId() { 
     return id; 
    } 

    public void setId(Integer id) { 
     this.id = id; 
    } 

    @Column(name = "ean") 
    public String getEan() { 
     return ean; 
    } 

    public void setEan(String ean) { 
     this.ean = ean; 
    } 

    @Column(name = "quantity") 
    public Integer getQuantity() { 
     return quantity; 
    } 

    public void setQuantity(Integer quantity) { 
     this.quantity = quantity; 
    } 

    @Column(name = "color") 
    public String getColor() { 
     return color; 
    } 

    public void setColor(String color) { 
     this.color = color; 
    } 



    @Column(name = "size") 
    public String getTaglia() { 
     return size; 
    } 




    public void setTaglia(String size) { 
     this.size = size; 
    } 



    @Column(name = "posizione") 
    public Integer getPos() { 
     return pos; 
    } 




    public void setPos(Integer pos) { 
     this.pos = pos; 
    } 




    @ManyToMany(fetch = FetchType.EAGER, mappedBy = "articles") 
    public Set<Model> getModels() { 
     return models; 
    } 

    public void setModels(Set<Model> models) { 
     this.models = models; 
    } 

    @Override 
    public String toString() { 
     return "Article [id=" + id + ", ean=" + ean + ", quantity=" + quantity + ", color=" + color + ", models=" 
       + models + "]"; 
    } 



} 
+0

あなたの財産がある記事と一致していません。 "article"ではなく "article"という名前です: 'getArticle()' –

+0

私は質問を閉じます、あなたの提案は正解です – Francesco

答えて

0

これは解決策です

Model.java:

package oodb; 

import static javax.persistence.GenerationType.IDENTITY; 

import java.util.HashSet; 
import java.util.Set; 

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.JoinColumn; 
import javax.persistence.JoinTable; 
import javax.persistence.ManyToMany; 
import javax.persistence.Table; 
import javax.persistence.UniqueConstraint; 



@Entity 
@Table(name = "model", catalog = "oogvg", uniqueConstraints = { 
     @UniqueConstraint(columnNames = "code")}) 
public class Model { 
    private Integer ModelId; 
    private String code; 
    private String description; 
    private Double cost; 
    private Double price; //selling price 
    private Set<Article> articles= new HashSet<Article>(0); // lista di articoli 

    public Model(){}; 

    public Model(String code, String description, Double cost, Double price) { 
     super(); 
     this.code = code; 
     this.description = description; 
     this.cost = cost; 
     this.price = price; 
    } 

    @Id 
    @GeneratedValue(strategy = IDENTITY) 
    @Column(name = "model_id", unique = true, nullable = false) 
    public Integer getModelId() { 
     return ModelId; 
    } 

    public void setModelId(Integer modelId) { 
     ModelId = modelId; 
    } 

    @Column(name = "code", unique = true, nullable = false, length = 10) 
    public String getCode() { 
     return code; 
    } 

    public void setCode(String code) { 
     this.code = code; 
    } 

    @Column(name = "description") 
    public String getDescription() { 
     return description; 
    } 

    public void setDescription(String description) { 
     this.description = description; 
    } 

    @Column(name = "cost") 
    public Double getCost() { 
     return cost; 
    } 

    public void setCost(Double cost) { 
     this.cost = cost; 
    } 

    @Column(name = "price") 
    public Double getPrice() { 
     return price; 
    } 

    public void setPrice(Double price) { 
     this.price = price; 
    } 


    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) 
    @JoinTable(name = "model_article", catalog = "oogvg", joinColumns = { 
      @JoinColumn(name = "model_id", nullable = false, updatable = false) }, 
      inverseJoinColumns = { @JoinColumn(name = "article_id", 
        nullable = false, updatable = false) }) 
    public Set<Article> getArticles() { 
     return articles; 
    } 

    public void setArticles(Set<Article> articles) { 
     this.articles = articles; 
    } 

    @Override 
    public String toString() { 
     return "Model [ModelId=" + ModelId + ", code=" + code + ", description=" + description + ", cost=" + cost 
       + ", price=" + price + "]"; 
    } 




} 

間違った部分:

@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) 
    @JoinTable(name = "model_article", catalog = "oogvg", joinColumns = { 
      @JoinColumn(name = "model_id", nullable = false, updatable = false) }, 
      inverseJoinColumns = { @JoinColumn(name = "article_id", 
        nullable = false, updatable = false) }) 
    public Set<Article> getArticle() { 
     return articles; 
    } 

    public void setArticle(Set<Article> article) { 
     this.articles = article; 
    } 

関数の名前が(悪い)(JB Nizedが言うように)