DataManager loader bug?

Hi,
I have a problem. When I load entity(s) via dataManager.load I get all related entities (in a one-to-many relationship) even if they are not in the fetch plan.

For example:

  val reports =  dataManager
        .load(Report::class.java)
        .all()
        .fetchPlanProperties("name")
        .list()

Query returns “templates” in entities.

This bug causes problems with entity updates.

Regards
Marcin

Hi Marcin,

I suppose you are talking about entities from the Reports add-on.

Most probably the related entities are loaded because you access a getter and lazy loading comes into play.
Consider the following test case:

@Autowired
private UnconstrainedDataManager dataManager;
@Autowired
private EntityStates entityStates;

@Test
void loadReports() {
	List<Report> reports = dataManager.load(Report.class)
			.all()
			.fetchPlanProperties("name")
			.list();
	for (Report report : reports) {
		assertTrue(entityStates.isLoaded(report, "name"));
		assertFalse(entityStates.isLoaded(report, "templates")); // not loaded

		report.getReportTemplates(); // lazy loading occurs here
		assertTrue(entityStates.isLoaded(report, "templates")); // loaded
	}
}