尝试映射未重复的 Set 类型对象(属性访问方法和 JPA 注释)时出错 [英] Error when trying to map a Set type object (Property access method and JPA annotation) not duplicated tho

查看:24
本文介绍了尝试映射未重复的 Set 类型对象(属性访问方法和 JPA 注释)时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In order to accomplish another task, I need redefine my pojos classes and use property access to take advantage of JavaFX properties in my mentioned classes, but I'm facing this error.

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

我已经尝试了org.hibernate.MappingException:无法确定类型:java.util.Setorg.hibernate.MappingException: 无法确定类型:java.util.List 但仍然无法使其工作.

I have already tryied the solutions mentioned in org.hibernate.MappingException: Could not determine type for: java.util.Set and org.hibernate.MappingException: Could not determine type for: java.util.List but still can't make it work.

这里是我的 OneToMany 实体类和 这里是我的 ManyToOne 类.

Here is my OneToMany entity class and here is my 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)

编辑

<小时>

这是我的 HibernateUtil 类.这个是出现在堆栈跟踪中的DAO.

Edit


This is my HibernateUtil class. This one is the DAO that appears in the stack trace.

在此先感谢您,这是我第一个使用 hibernate 的项目……或者确实是我的第一个项目.

Thank you in advance, this is my first project using hibernate... Or my first project at all indeed.

推荐答案

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

In your Deposito class I see that your JPA annotation is on the property and not on the getter like everywhere else in the class (I doubt this is your problem, but maybe a good idea to be consistent)

这里有:

@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" 指向这个方法(这可能不是你想要的):

referencedColumnName = "descripcion_deposito" point to this method (which is probably not the one you intended):

@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 类中:

I'm not sure exactly what your column names are, but the referencedColumnName should point to the primary/foreign key of the field of the Productos object, try this in the 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();
  }
}

这篇关于尝试映射未重复的 Set 类型对象(属性访问方法和 JPA 注释)时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆