Wiring ComputedAttribute/ComputedRelationship with transactions
Problem Description
I have a use case where I have a @ComputedAttribute getter in the model, and it return a private transient field which should be set by something from the transaction. To make it clear:
@Setter private String url; // not a column in the database
@Transient
@ComputedAttribute
public String getUrl() {
return url;
}
In my transaction impl, I have a DAO that will load url from another service based on some other attributes of the model, and set the url to the model. And I call the DAO methods in the load functions inherited from DataStoreTransaction, so GET requests work perfectly(the computed fields are showing correctly).
However, when making a POST/PUT/PATCH requests to create this resource, the url field in the JSON response shows null, I see that the Persistence.toResource method simply calls the getters of the attributes, and thus the url field is not properly set by the DAO.
Ask
I wonder if returning null for computed things on creation is a good experience or not. If I want the computed fields to show up correctly, we may want to wire the computed methods somehow with the transaction, or provide some injection point in the PersistenceResource.
I know that we have plan to delegate setAttribute/getAttribute/updateAttribute from PersistenceResource to DataStoreTransaction in Elide 3.0, I wonder would this issue be resolved when that's finally in place.
Any thoughts?
I think this is strongly related to #234 and merits investigation. It could be the case that mapping DAOs to web services (at least in some corner cases) is necessary and would require custom object instantiation.
setAttribute is now invoked in DataStoreTransaction (since Elide 6)