Skip to content

EntityDefinition ignored when it's a shallow reference #1327

Closed
@cberes

Description

@cberes

When using EntityDefinitionBuilder.withShallowProperties, registering an EntityDefinition can cause subsequent EntityDefinitions to be ignored.

For example, say I have 2 classes, where one class has a shallow reference to the other.

class ValueObjectHolder {
    @Id int id
    Set<SetValueObject> valueObjects
}

class EntityHolder {
    @Id int id
    ValueObjectHolder valueObjectHolder
}

and I register the classes in this order

javers()
  .registerEntity(EntityDefinitionBuilder
          .entityDefinition(EntityHolder.class)
          .withIdPropertyName('id')
          .withIncludedProperties(['id', 'valueObjectHolder'])
          .withShallowProperties(['valueObjectHolder'])
          .build())
  .registerEntity(EntityDefinitionBuilder
          .entityDefinition(ValueObjectHolder.class)
          .withIdPropertyName('id')
          .withIncludedProperties(['id', 'valueObjects'])
          .build())
  .build()

The entity definition for ValueObjectHolder will be ignored. Any type name or properties I set for ValueObjectHolder will not be used.

It seems to be related to the shallow reference in EntityHolder. If I omit the call to withShallowProperties, the entity definitions are registered as expected.

Steps To Reproduce

I have a PR with a failing test. The tests are in org/javers/core/JaversDiffE2ETest.groovy. There are 2 tests:

  • should use entity definition for entity that is not a shallow reference passes; does not use withShallowProperties
  • should use entity definition for entity that is a shallow reference fails; same as above but it uses withShallowProperties

Javers' Version
7.3.2+

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions