Entity inheritance has a small issue - Platform 6.10.7

I think Entity inheritence has a small issue/limitation when creating a new instance of a sub-entity.

The initNewItem method in the AbstractEditor class is defined as being called with the sub-class of the entity but at this point in the logic the actual class passed to the setItem method which calls the user hook setNewItem is called with the PARENT class so a class-cast exception is always thrown at this point. Later on in the setItem method the sub-class is determined correctly and any subsequent getItem call returns the correct sub-class.

There is a workaround for this in that the setItem method in AbstractEditor calls the postInit user hook at which time this method can call getItem to process the sub-class. However the slight issue here is that postInit can be called at other times under certain circumstances and this MAY not be desireable depending on what was intended in the user code.

I can understand that this may be a catch-22 situation (I’m not familiar enough with this code yet to determine if this is fixable) so if it is then this can only be a documentation fix to identify the restriction on using setNewItem when using inheritence entities.

I should have added that this can be recreated easily by adding a call to setNewItem in either of the sub-entity edit controllers in the sample project at GitHub - cuba-platform/sample-entity-inheritance: DEPRECATED. See https://www.cuba-platform.com/guides/data-modelling-entity-inheritance

Andrew.

Hi Andrew,

Probably the problem can be resolved if we provide some method to pass the entity of the correct class to CreateAction as @tom.monnier suggested here.
Created issue.

This is really amazing when different people come across the same problem (which always existed) almost simultaneously :slight_smile:

Regards,
Konstantin

I have to admit I hadn’t checked to see if anybody else had reported the problem which is a cardinal sin I know! In my defence though I don’t think I woudl have spotted the other issue as it appears to see the problem from a different angle (at least it doesn’t use any of the words I used :slight_smile: ).

Anyway glad to see some sort of fix will come one day - thank you Konstantin.

Andrew