无法确定表的类型:java.util.Set [英] Could not determine type for: java.util.Set, at table

查看:103
本文介绍了无法确定表的类型:java.util.Set的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建两个类,它们之间具有多对多的关系,如下所示:

I create two classes with many to many relation between them, like as below:

@Entity
@Table(name = FoodEntity.TABLE_NAME)
public class FoodEntity extends BaseEntity<Long> {

public static final String TABLE_NAME = "T_FOOD";

@ManyToMany
@JoinTable(
    name = "T_FOOD_FOODCATEGORY",
    joinColumns =       { @JoinColumn(name = "FOOD_ID") }, 
    inverseJoinColumns =    { @JoinColumn(name = "FOOD_CATEGORY_ID") })
private Set<FoodCategoryEntity> categories;

public Set<FoodCategoryEntity> getCategories() {
return categories;
}

public void setCategories(Set<FoodCategoryEntity> categories) {
this.categories = categories;
}

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "FOOD_ID", nullable = false)
@Override
public Long getId() {
return id;
}

@Override
public void setId(Long id) {
this.id = id;
}

}

和:

@Entity
@Table(name = FoodCategoryEntity.TABLE_NAME)
public class FoodCategoryEntity extends BaseEntity<Long> {

public static final String TABLE_NAME = "T_FOOD_CATEGORY";

@ManyToMany(mappedBy = "categories")
private Set<FoodEntity> foods;

public Set<FoodEntity> getFoods() {
return foods;
}

public void setFoods(Set<FoodEntity> foods) {
this.foods = foods;
}

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "FOOD_CATEGORY_ID", nullable = false)
@Override
public Long getId() {
return id;
}

@Override
public void setId(Long id) {
this.id = id;
}

}

但是当我用junit,spring和hibernate测试这种关系时,出现以下异常:

but when I test this relation with junit,spring and hibernate, I get below exception:

Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: T_FOOD, for columns: [org.hibernate.mapping.Column(categories)]
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.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:889)
... 46 more

我检查了注释包引用以及所有ID列名称,但它们都是正确的. 要点:我还使用了HSQLDB数据库,该数据库的存储位置是文件.

I checked annotation package references, and all ID column names, but all of them are correct. point : I also use the HSQLDB database whose storage location it is a file.

推荐答案

我发现了我的问题. persistence.xml中的映射类不正确.

I found my problem. mapping class in persistence.xml was incorrect.

这篇关于无法确定表的类型:java.util.Set的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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