Java 如何与Hibernate和Kotlin建立正确的多人关系?(获取BeanCreationException)
我有以下引发以下异常的代码:Java 如何与Hibernate和Kotlin建立正确的多人关系?(获取BeanCreationException),java,spring,hibernate,kotlin,Java,Spring,Hibernate,Kotlin,我有以下引发以下异常的代码: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation o
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: project, for columns: [org.hibernate.mapping.Column(type)]
我认为我以错误的方式创建了@manytoman映射。以下是有关的主要课程:
@Entity
class Project (
@GeneratedValue
@Id
var id : UUID? = null,
var owner: Int,
@get:ManyToMany(mappedBy = "project", fetch = FetchType.EAGER)
var type: MutableSet<Type> = mutableSetOf()
)
@实体
班级项目(
@生成值
@身份证
变量id:UUID?=null,
var所有者:Int,
@get:ManyToMany(mappedBy=“project”,fetch=FetchType.EAGER)
变量类型:MutableSet=mutableSetOf()
)
第二类是:
class Type(
@GeneratedValue
@Id
var id: UUID? = null,
var oldId: Int,
var value: String,
@get:ManyToMany(fetch = FetchType.EAGER)
@get:JoinColumn(name = "project_id")
var projects: MutableSet<Project> = mutableSetOf()
)
类类型(
@生成值
@身份证
变量id:UUID?=null,
变量oldId:Int,
变量值:字符串,
@get:ManyToMany(fetch=FetchType.EAGER)
@获取:JoinColumn(name=“project\u id”)
var项目:MutableSet=mutableSetOf()
)
一个项目可以有许多类型,一个类型可以属于许多项目。导致异常的原因是什么?更改
@get:ManyToMany
@get:JoinColumn
到
在
项目
实体中
@get:ManyToMany(mappedBy = "project", fetch = FetchType.EAGER)
var type: MutableSet<Type> = mutableSetOf()
这应该很好用。希望有帮助。类类型中是否添加了@entity?不,这就是问题所在,谢谢!所以问题解决了?
@get:ManyToMany(mappedBy = "project", fetch = FetchType.EAGER)
var type: MutableSet<Type> = mutableSetOf()
@get:ManyToMany(mappedBy = "projects", fetch = FetchType.EAGER)
var type: MutableSet<Type> = mutableSetOf()