morphia icon indicating copy to clipboard operation
morphia copied to clipboard

getEntityModel on @ExernalEntity anntotated class fails when called more than once

Open itdv opened this issue 1 year ago • 2 comments

Description Suppose we have the following:

public class ThirdPartyEntity {
    public String field;
    public Long number;
}

and

@ExternalEntity(target = ThirdPartyEntity.class)
public class ThirdPartyEntityMixIn {
    public String field;
    @Id
    public Long number;
}

When calling datastore.getMapper().getEntityModel(ThirdPartyEntityMixIn.class), the entity model of ThirdPartyEntity is returned correctly the first time. However, on the second call, getEntityModel fails due to a duplicated discriminator error: Two entities have been mapped using the same discriminator value (com.example.ThirdPartyEntityMixIn): com.example.ThirdPartyEntity and com.example.ThirdPartyEntity

Cause The issue occurs because when entities are being put into mappedEntities, the key used is entityModel.getType(), which refers to ThirdPartyEntity.class. But when retrieving the model in getEntityModel, the key used is ThirdPartyEntityMixIn.class, leading to a conflict when Morphia attempts to register the entity again.

Morphia Version: 2.4.4

itdv avatar Sep 05 '24 06:09 itdv

I'll try to dig in to this tonight.

evanchooly avatar Sep 05 '24 19:09 evanchooly

Well, "tonight" turned in to months. I can't recreate this on master/2.4.14. If you could put together a reproducer I'd be happy to take another look. For now I'll remove this from 2.4.15 because we're long overdue for a release.

evanchooly avatar Feb 27 '25 02:02 evanchooly