I have a simple domain model (see attached project). A “Company” has many “Factories”.
I would like to display a comma separated list for all factories in the company browse page. I also have a case, where I display this list in the edit page for an entity (this is not done in the demo project).
This is achieved by defining a transient property in the entity that creates a string with all factories. This works find when I use the correct view. But when I try to open the the Company instance in the “Entity inspector” I receive a HTTP 500 error.
My opinion is that I am doing something wrong in cuba, when core features (like the “Entity inspector”) are no longer working.
How would your recommend to solve this problem? Or is there a way to fix the Entity inspector? Thanks in advance.
The problem is that Entity Inspector uses an automatically created view which includes only local and to-one attributes. But your factoryList attribute requires loading of one-to-many attribute factories, which is not in the view.
There is a way to indicate for generic mechanisms like Entity Inspector that some persistent attributes must be loaded for a non-persistent attribute to be calculated: related parameter of the @MetaProperty annotation. So in your case it is enough to set for the factoryList attribute:
public class Company extends StandardEntity {
@Composition
@OnDelete(DeletePolicy.CASCADE)
@OneToMany(mappedBy = "company")
protected Set<Factory> factories;
@Transient
@MetaProperty(related = {"factories"})
protected String factoryList;
After that, Entity Inspector will work correctly with the Company entity.