尝试映射Set类型对象(属性访问方法和JPA注释)时出错,而不是重复 [英] Error when trying to map a Set type object (Property access method and JPA annotation) not duplicated tho
问题描述
为了完成另一项任务,我需要重新定义我的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.Set 和 org.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
class:
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屋!