org.hibernate.LazyInitializationException:无法延迟初始化集合

时间:2019-08-09 11:34:52

标签: java

这是我的代码。

public interface EmployeRepository extends CrudRepository<Employe, Integer>         
{}


@Entity
public class Employe implements Serializable {

private static final long serialVersionUID = -1396669830860400871L;

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;

private String prenom;

private String nom;

//@Column(unique=true)
private String email;

private boolean isActif;

@Enumerated(EnumType.STRING)
//@NotNull
private Role role;


@ManyToMany(mappedBy="employes" )
//@NotNull
private List<Departement> departements;

}

我遇到此错误:

Exception in thread "main" org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: tn.esprit.spring.entities.Departement.employes, could not initialize proxy - no Session

请,您对此错误有一个了解吗?我必须像crud存储库一样将主键更改为整数?

非常感谢。

0 个答案:

没有答案
相关问题