尝试映射 Set 类型对象时出错(属性 访问方法和 JPA 注释)未重复

Error when trying to map a Set type object (Property access method and JPA annotation) not duplicated tho

为了完成另一项任务,我需要重新定义我的 pojos classes 并使用 属性 访问来利用我提到的 classes 中的 JavaFX 属性,但是我'我面临这个错误。

org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: deposito, for columns: [org.hibernate.mapping.Column(productoses)]

我已经尝试了org.hibernate.MappingException: Could not determine type for: java.util.Set and org.hibernate.MappingException: Could not determine type for: java.util.List中提到的解决方案,但仍然无法实现。

Here is my OneToMany entity class and here 是我的 ManyToOne class.

这是堆栈跟踪。

org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: deposito, for columns: [org.hibernate.mapping.Column(productoses)]
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:455)
    at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:422)
    at org.hibernate.mapping.Property.isValid(Property.java:226)
    at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:597)
    at org.hibernate.mapping.RootClass.validate(RootClass.java:265)
    at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:451)
    at org.hibernate.boot.internal.MetadataImpl.buildSessionFactory(MetadataImpl.java:170)
    at ajfmo.inventario.utils.HibernateUtil.getSessionFactory(HibernateUtil.java:19)
    at ajfmo.inventario.DAO.ProductDAO.<init>(ProductDAO.java:20)
    at ajfmo.inventario.view.MainView.<init>(MainView.java:60)

编辑


This is my HibernateUtil class. This 一个是堆栈跟踪中出现的 DAO。


提前谢谢你,这是我第一个使用 hibernate 的项目......或者说是我的第一个项目。

在您的 Deposito class 中,我看到您的 JPA 注释在 属性 上,而不是在 getter 上,就像 class 中的其他地方一样(我怀疑这是你的问题,但保持一致可能是个好主意)

这里你有:

@OneToMany(fetch = FetchType.LAZY, mappedBy = "deposito")
private Set<Productos> productoses = new HashSet<Productos>(0);

public Set<Productos> getProductoses() {
  return this.productoses;
}

Productos class 你有:

private ObjectProperty<Deposito> deposito;
private Deposito _deposito;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "deposito_producto", referencedColumnName = "descripcion_deposito", nullable = false)
public Deposito getDeposito() {
  if (deposito == null) {
    return _deposito;
  } else {
    return deposito.get();
  }
}

referencedColumnName = "descripcion_deposito" 指向此方法(可能不是您想要的方法):

@Column(name = "descripcion_deposito", unique = true, nullable = false, length = 45)
public String getDescripcionDeposito() {
  if (descripcionDeposito == null) {
    return _descripcionDeposito;
  } else {
    return descripcionDeposito.get();
  }
} 

我不确定你的列名到底是什么,但是 referencedColumnName 应该指向 Productos 对象字段的 primary/foreign 键,在Productos class:

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "deposito_producto", referencedColumnName = "idDeposito", nullable = false)
public Deposito getDeposito() {
  if (deposito == null) {
    return _deposito;
  } else {
    return deposito.get();
  }
}