Parent Attributes into Child Object


I am new to Cube platform and I am still trying to get to grips with the basics so apologies if this is a ‘stupid’ question.

I have a situation where I have created a batch screen and one of the attributes of the batch object is a parent (InputBatch) which I want to the user to select. I have managed to get that working out of the box with no issues.

However I now want to extend that slightly, the batch screen also has an attribute ‘type’. I have added this to the batch in the data model and it is a real object linked via association (many-to-one). This attribute is also present in the parent and to make things easier I do not want the user to have to pick it again, I want to auto assign this when they pick the parent object.

Via the security model I have actually made this field read-only for my data entry user and I have attempted following the standard examples to add code into a middleware service bean that shall assign these values. I am injecting the bean into the edit class (BatchEdit extends AbstractEditor) and calling the bean from the method preCommit().

However when I do this I keep getting the same error: IllegalStateException: Cannot get unfetched attribute [typeS] from detached object

In the Data model I have created a view (again following the examples) and I have added in (ticked) all the parameters for both the parent (including type below it as well) and the type object. I had hoped following from other posts I had read that this would fix but no it did not work.

I then thought it might be better to move this logic to an EntityListener but that made no difference either and I still get the same error.

Can anyone help me or point me in the right direction?


Hi Iain,

So you have defined a view including the needed reference attribute, but where do you use this view?
And when do you get the exception? At the moment of getting the value from the parent object?

Hi Konstantin,

I have solved this. I was asking the parent object for specific attributes in the Service bean and then the error was being thrown. I checked the view from which the parent was selected and it turns out that the attribute I was looking was not available in there. I updated this and then it worked fine.

Hopefully what I said there made sense? Still just getting familiar with the framework, which I really like by the way!

Also managed to work out how to assign the values using this post (How to change field value based on drop down field - CUBA.Platform) and the manual.


Good to hear that you solved the problem.
Without looking to the code, I cannot say how optimal it is, but usually you don’t need a service just to assign some values to an entity - it can be done right in the screen controller.