How to load a full entity with all relations

Hello,

Question: How to load an entity with all data and relations in the custom code?

Context:
I have a table with Entities. I’m trying to implement my custom action similar to “Excel”.
Only some basic data is showing in my table, but I have to export all data and relations.

I tried to add children collection data sources but have got “IllegalStateException: Cannot get unfetched attribute [attribute_name] from detached object.”

What is the best way to achieve this? Thanks!

I am assuming you are using a LoadContext to retrieve data. In a LoadContext, you have the option to specify the view to use. If you don’t specify a view to use, I believe it defaults to the “local” view which excludes any foreign references.

LoadContext<YourEntity> context = LoadContext.create(YourEntity.class)
				.setQuery(LoadContext.createQuery(
						"select e from deiproductconfig2$YourEntity e ))
				.setView("YourEntity-view");
2 Likes

Thanks, Weston Jones!

I’m using partially loaded entity in actionPerform() action method.

What I did to load it completely:

  1. Created new entity view with all needed fields and relations.
  2. In the actionPerform() method called dataManager.reload() method:

Entity selectedEntity = listComponent.getSingleSelected();
Entity fullEntity = dataManager.reload(selectedEntity, "my-entity-full-view");

Looks like it works for me. Can it be a solution? :slight_smile:

2 Likes