这是我的实体类:
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="seqGenDoc")
private long id;
private String label;
private String path;
@ManyToOne
@JoinColumn(name="CODE_USER_GENERATEDBY")
private User generatedBy;
private float version;
//@Temporal(TemporalType.DATE)
private Instant creationDate;
@OneToMany(mappedBy="documentGenerated",fetch=FetchType.LAZY)
private Collection<GeneratedDocumentFields> listDocFields;
@OneToMany(mappedBy="generatedDocument",fetch=FetchType.LAZY)
private Collection<HistoryDocument> listHistoryDoc;
这是我的查询功能:
public interface GeneratedDocumentRepository extends JpaRepository<GeneratedDocument, Long> {
@Transactional(readOnly=true)
@Query("select gd from GeneratedDocument gd left join fetch gd.generatedBy gb where gb.id=:x")
public List<GeneratedDocument> ListGenDocByUser(@Param("x")Long id);
我只是调用函数:
public void run(String ... args)引发异常{ System.out.println(generatedDocumentRepository.ListGenDocByUser((long) 803));
这是完整的错误:
无法延迟初始化角色集合: fr.etech.eliteerp.entities.GeneratedDocument.listDocFields,无法 初始化代理-没有会话
但是,我每次都会遇到相同的问题。
答案 0 :(得分:0)
将@Transactional
添加到执行查询的方法中。