【问题标题】:Error when trying to map a Set type object (Property access method and JPA annotation) not duplicated tho尝试映射不重复的 Set 类型对象(属性访问方法和 JPA 注释)时出错
【发布时间】:2018-07-26 20:08:43
【问题描述】:

为了完成另一项任务,我需要重新定义我的 pojos 类并使用属性访问来利用我提到的类中的 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.Setorg.hibernate.MappingException: Could not determine type for: java.util.List 中提到的解决方案,但仍然无法成功。

Here 是我的 OneToMany 实体类,here 是我的 ManyToOne 类。

这是堆栈跟踪。

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 是我的 HibernateUtil 类。 This 一个是出现在堆栈跟踪中的 DAO。


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

【问题讨论】:

  • 所以查看堆栈跟踪问题似乎在HibernateUtil 类中。它由ProductDAOclass 调用,由MainView 类调用。您应该发布那些而不是您发布的课程。这会有很大帮助。另请查看this 以帮助人们解决您的问题。
  • @MarkusK 感谢您的评论。我编辑了帖子并添加了这两个类,但我认为问题不是来自那里,我认为是注释但仍然没有找到解决方法。

标签: jpa javafx annotations javafx-8


【解决方案1】:

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

你有:

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

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

Productos 类中你有:

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 对象字段的主键/外键,在Productos 类中试试这个:

@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();
  }
}

【讨论】:

  • @nicolschl 非常感谢!确实问题是注释放错了地方。为了以防万一,“producto”显然是产品而“deposito”是仓库,许多产品有一个仓库,一个仓库有很多产品,在我的产品表中有一个名为“deposito_productos”的varchar列,这是一个FK “descripcion_deposito”,我发现这种方式在检索数据时更容易一些,不太确定,但到目前为止我需要它工作正常,我知道将来我将不得不使用这种关系主键/外键。 10 倍!
猜你喜欢
  • 2012-07-28
  • 2021-06-19
  • 2012-03-18
  • 1970-01-01
  • 1970-01-01
  • 2019-12-06
  • 1970-01-01
  • 2017-09-12
  • 1970-01-01
相关资源
最近更新 更多