A
A
Andrey Sukhanov2016-12-23 11:52:59
Java
Andrey Sukhanov, 2016-12-23 11:52:59

How to work in tests with services during Lazy Initialization?

Need help from those who know Spring.
There is an entity:
@Entity
public class Document {
...
blah blah blah
...
@OneToMany(mappedBy = "document")
@JsonIgnore
private Collection links;
}
There is also an entity of links to which the document refers
public class DocumentLink {
...
blah blah blah
...
}
There is a test for accessing the document
@Test
@Transactional
public void test() throws Exception {
documentLinkRepository.findByDocumentId(504L )
documentService.getDocumentLinks(504);
}
When referring to a document service that receives links by document id, I expect all links of the document to be displayed, but for some reason the list is empty.
Although, at the same time, when searching for links through the repository, a non-empty list is returned.
How and what to do with it?)
GetDocumentLinks implementation:
@Override
@Transactional(readOnly = true)
public Collection getDocumentLinks(long documentId) throws DocumentNotFoundException {
Document document = this.getDocumentById(documentId);
return document.getLinks();
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question