我在使用 Hibernate 持久化实体权限时遇到问题。我需要保存许多权限对象,其中有一个属性组(外键),但在保存权限的同时,我正在保存组,所以我没有要设置的组 ID(主键)建立关联的权限对象。
我的关系:
@Entity
@BatchSize(size = 10)
public class Group implements Serializable {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "grupo")
@JsonIgnore
private List<Permissao> permissoes;
}
@Entity
@BatchSize(size = 10)
public class Permission implements Serializable {
@ManyToOne
private Grupo grupo;
}
堆:
SEVERE: Servlet.service() for servlet [hemisphere-web] in context with path
[/hemisphere-web] threw exception [Request processing failed; nested exception is
org.springframework.dao.InvalidDataAccessApiUsageException:
org.hibernate.TransientPropertyValueException: object references an unsaved transient
instance - save the transient instance before flushing:
net.pontoall.hemisphere.core.model.Permission.grupo ->
net.pontoall.hemisphere.core.model.Grupo; nested exception is
java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: object
references an unsaved transient instance - save the transient instance before flushing:
net.pontoall.hemisphere.core.model.Permissao.grupo ->
net.pontoall.hemisphere.core.model.Grupo] with root cause
org.hibernate.TransientPropertyValueException: object references an unsaved transient
instance - save the transient instance before flushing:
net.pontoall.hemisphere.core.model.Permissao.grupo -> net.pontoall.hemisphere.core.model.Grupo
有人可以给我一个提示吗?