Foreign key columns are not being preloaded by default

Description

Given the following ParentEntity:

1 2 3 4 5 6 7 8 @Preload public interface ParentEntity extends Entity { public String getName(); public void setName(String name); @OneToMany(reverse = "getParent") public ChildEntity[] getChildren(); }

And the following ChildEntity:

1 2 3 4 5 6 7 8 @Preload public interface ChildEntity extends Entity { public String getName(); public void setName(String name); public ParentEntity getParent(); public void setParent(ParentEntity parent); }

Here's what happens, when a child entity is being accessed:

1 2 3 4 ChildEntity childEntity = ao.get(ChildEntity.class, 123); // -> SELECT ID,NAME FROM AO_X1Y1Z2_CHILD_ENTITY WHERE ID = ? childEntity.getID(); // preloaded -> no additional query executed childEntity.getName(); // preloaded -> no additional query executed childEntity.getParent().getID(); // -> SELECT PARENT_ID FROM AO_X1Y1Z2_CHILD_ENTITY WHERE ID = ?

In my opinion, when declaring @Preload (which should be the same as @Preload("*")) on the child entity, the column PARENT_ID should have been preloaded as well in the first query and the last query shouldn't really be necessary at all. The impact of this behavior is even bigger, when e.g. you need to loop over a set of child entities and need to get the parent ID to build a link to the parent entity.

Workaround

The current workaround is to explicitly list all the columns of the child entity in the @Preload annotation:

1 @Preload({ "ID", "NAME", "PARENT_ID" })

If this works as designed, there should at least be a note in the @Preload documentation.

Environment

None

Testing Notes

Add notes...

Status

Assignee

Unassigned

Reporter

Remo Siegwart

Labels

None

Add-on Type

None

Team

None

CC

None

Risk factor

None

QA Kickoff Status

None

QA Demo Status

None

Components

Priority

Minor
Configure