2个类之间的映射错误,无法建立Hibernate SessionFactory;

时间:2019-05-07 14:43:11

标签: hibernate jpa mapping

我尝试运行我的项目,但出现此错误: org.springframework.beans.factory.BeanCreationException:在类路径资源[org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaConfiguration.class]中创建名称为'entityManagerFactory'的bean时出错:调用init方法失败;嵌套的异常是javax.persistence.PersistenceException:[PersistenceUnit:默认]无法构建Hibernate SessionFactory。嵌套的异常是org.hibernate.MappingException:无法确定类型:java.util.Collection,在表:objet_modele,对于列:[org.hibernate.mapping.Column(modeles_by_objet_id)]  这是实体:

       @Entity
     @Table(name = "modele", schema = "public", catalog = "pfeDb")
    public class ModeleEntity
   {
   private int objetId;
   @Id
   @Column(name = "objet_id", nullable = false)
 public int getObjetId() {
     return objetId;
    }

  public void setObjetId(int objetId) {
    this.objetId = objetId;
  }
     @ManyToOne
     @JoinColumn(name = "objetModeleByObjetId")
    private ObjetModeleEntity objetModeleByObjetId;


 public ObjetModeleEntity getObjetModeleByObjetId() {
   return objetModeleByObjetId;
 }

public void setObjetModeleByObjetId(ObjetModeleEntity 
  objetModeleByObjetId) {
  this.objetModeleByObjetId = objetModeleByObjetId;
 }

 }

第二个:

       @Entity
   @Table(name = "objet_modele", schema = "public", catalog = "pfeDb")
     public class ObjetModeleEntity 
     {
  @Id

     private String idModele;

  @OneToMany(mappedBy = "objetModeleByObjetId")
    private Collection<ModeleEntity> modelesByObjetId;


 public Collection<ModeleEntity> getModelesByObjetId() {
     return modelesByObjetId;
   }

    public void setModelesByObjetId(Collection<ModeleEntity> 
    modelesByObjetId) {
   this.modelesByObjetId = modelesByObjetId;
 }
  }

谢谢您的帮助:)

0 个答案:

没有答案