Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
itdv opened this issue Sep 5, 2024 · 1 comment
Labels

Comments

@itdv
Copy link

itdv commented Sep 5, 2024

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 itdv added the bug label Sep 5, 2024
@evanchooly
Copy link
Member

I'll try to dig in to this tonight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants