Inheritance bugs

I have two bugs

I have

@JmixEntity
@MappedSuperclass
abstract class BaseEntitySoftDelete : BaseEntity() {
    //@DeletedBy
    @Column(name = "DELETED_BY")
    open var deletedBy: String? = null

    //@DeletedDate
    @Column(name = "DELETED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    open var deletedDate: Date? = null
}

@JmixEntity
@Table(name = "TEST_BASE_ENTITY_SOFT_DELETE", indexes = [
    Index(name = "IDX_TEST_BASE_ENTITY_SOFT_DELETE_PARENT", columnList = "PARENT_ID")
])
@Entity
open class TestBaseEntitySoftDelete : BaseEntitySoftDelete() {
    @NotBlank
    @NotEmpty
    @InstanceName
    @Column(name = "NAME", nullable = false)
    @NotNull
    var name: String? = null

    @JoinColumn(name = "PARENT_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    var parent: TestBaseEntity? = null

    @DeletedBy
    @Column(name = "DELETED_BY")
    override var deletedBy: String? = null

    @DeletedDate
    @Column(name = "DELETED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    override var deletedDate: Date? = null
}

If I don’t override deletedBy and deletedDate to add annotation but set annotation in the parent class I have a strange behavior of a not deletable entity !!!

Other bug with

@JmixEntity
@MappedSuperclass
abstract class BaseComment<T: BaseEntity> : BaseEntity() {
    @Column(name = "COMMENT_", nullable = false)
    @Lob
    @NotNull
    open var comment: String? = null

    @NotNull
    @Column(name = "DATE_", nullable = false)
    @Temporal(TemporalType.DATE)
    open var date: Date? = null

    @JoinColumn(name = "USER_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    open var user: User? = null
}

@JmixEntity
@Table(name = "COM_SOME_ENTITY_COMMENT", indexes = [
    Index(name = "IDX_COM_SOME_ENTITY_COMMENT_SOME_ENTITY", columnList = "SOME_ENTITY_ID")
])
@Entity(name = "com_SomeEntityComment")
open class SomeEntityComment : BaseComment<SomeEntity>() {
    @JoinColumn(name = "SOME_ENTITY_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    var someEntity: SomeEntity? = null

    @Column(name = "COMMENT_", nullable = false)
    @Lob
    @NotNull
    override var comment: String? = null

    @NotNull
    @Column(name = "DATE_", nullable = false)
    @Temporal(TemporalType.DATE)
    override var date: Date? = null

    @JoinColumn(name = "USER_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    override var user: User? = null
}

If I don’t override comment, date and user in SomeEntityComment I have a spring error


Exception [EclipseLink-60] (Eclipse Persistence Services - 2.7.9.6-jmix): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [_persistence_set_user_vh] or [_persistence_get_user_vh] is not defined in the object [com.company.addon.commons.entity.SomeEntityComment].
Internal Exception: java.lang.NoSuchMethodException: com.company.addon.commons.entity.SomeEntityComment._persistence_get_user_vh()
Mapping: org.eclipse.persistence.mappings.ManyToOneMapping[user]
Descriptor: RelationalDescriptor(com.company.addon.commons.entity.SomeEntityComment --> [DatabaseTable(COM_SOME_ENTITY_COMMENT)])

Exception [EclipseLink-218] (Eclipse Persistence Services - 2.7.9.6-jmix): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A NullPointerException would have occurred accessing a non-existent weaved _vh_ method [_persistence_get_user_vh].  The class was not weaved properly - for EE deployments, check the module order in the application.xml deployment descriptor and verify that the module containing the persistence unit is ahead of any other module that uses it.

Hello, @b.vallettedosia !
Sorry for the late reply.

I’ve tried to reproduce the issue by provided information on Jmix 1.5.1 and did not succeed.
Here is my project:
ib_test.zip (104.9 KB)

It works fine for following steps:

  1. Open it
  2. Recreate database
  3. Run com.company.ib_test.tests.CommonTest#test_saveTestBaseEntitySoftDelete

ER=AR: test passed

The test contains expected behavior for a simple soft-deletion case: a soft-deletion of an entity, loading of the deleted entity in usual way (no entity loaded) and loading of entity without soft-deletion mechanism (soft deleted entity is loaded).

I didn’t know how TestBaseEntity has been defined and had to use TestBaseEntitySoftDelete instead.

Could you please provide a minimal reproducible example for both problems with steps and expected/actual behaviour?

The initial commit run all test OK, the last commit remove “the fix” and test are KO

Hello, @b.vallettedosia

Unfortunately, I did not find any usage of soft deletion specific flags (jmix.softDeletion) and other ways to load entities without soft-deletion in your project. So it is not obvious for me, why entity considered as not deletable or what “strange behavior” means.

Moreover, I cannot even understand the structure of the tests because they were written using cucumber in French language which I don`t know.
This makes it really difficult to investigate the problem, not to mention discussion and description of what happens.

Please, provide a standard project that

  • uses a simple unit test (e.g. JUnit) like in the project I attached above,
  • uses English language for method names and in other places required to understand what happens,
  • have some description of what happens in the test and what result you expect.

Regards,
Dmitry

OK, to help you, I reset the repo, translated my features in english and set up the build in github

In the first commit Initial, build and tests are OK (with my fixes) Initial · bvopro/sample-commons@16d28cd · GitHub

In the commit TestBaseEntitySoftDelete as it should be I remove the fix for soft delete entity where I override fields, the results are that behavior change and tests are KO as you can see TestBaseEntitySoftDelete as it should be · bvopro/sample-commons@43d5bb3 · GitHub

2023-04-29T16:20:27.050+0000 [DEBUG] [TestEventLogger]     Failed scenarios:
2023-04-29T16:20:27.051+0000 [DEBUG] [TestEventLogger]     classpath:fr/altereo/features/addon/commons/model/commons.baseentity.softdelete.feature:20 # Create and delete a soft deletable entity
2023-04-29T16:20:27.051+0000 [DEBUG] [TestEventLogger]     classpath:fr/altereo/features/addon/commons/model/commons.baseentity.softdelete.feature:26 # Delete a soft deletable entity linked to another entity
2023-04-29T16:20:27.051+0000 [DEBUG] [TestEventLogger]     classpath:fr/altereo/features/addon/commons/model/commons.baseentity.softdelete.feature:33 # Delete soft deletable entities collection linked to another entity
2023-04-29T16:20:27.051+0000 [DEBUG] [TestEventLogger] 
2023-04-29T16:20:27.051+0000 [DEBUG] [TestEventLogger]     10 Scenarios (3 failed, 7 passed)
2023-04-29T16:20:27.051+0000 [DEBUG] [TestEventLogger]     33 Steps (3 failed, 1 skipped, 29 passed)
2023-04-29T16:20:27.052+0000 [DEBUG] [TestEventLogger]     0m27.937s
2023-04-29T16:20:27.052+0000 [DEBUG] [TestEventLogger] 
2023-04-29T16:20:27.052+0000 [DEBUG] [TestEventLogger] 
2023-04-29T16:20:27.053+0000 [DEBUG] [TestEventLogger]     org.opentest4j.AssertionFailedError: 
2023-04-29T16:20:27.053+0000 [DEBUG] [TestEventLogger]     expected: null
2023-04-29T16:20:27.053+0000 [DEBUG] [TestEventLogger]      but was: fr.altereo.addon.commons.entity.TestBaseEntitySoftDelete-dcf924c1-458d-2da0-b936-7a13ef5182c1 [detached]
2023-04-29T16:20:27.053+0000 [DEBUG] [TestEventLogger]     	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
2023-04-29T16:20:27.054+0000 [DEBUG] [TestEventLogger]     	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
2023-04-29T16:20:27.054+0000 [DEBUG] [TestEventLogger]     	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
2023-04-29T16:20:27.054+0000 [DEBUG] [TestEventLogger]     	at fr.altereo.features.addon.commons.CommonsBaseEntitySoftDeleteSteps.onNeTrouvePasLEnregistrementName(CommonsBaseEntitySoftDeleteSteps.kt:58)
2023-04-29T16:20:27.054+0000 [DEBUG] [TestEventLogger]     	at ✽.we find an TestEntitySoftDelete with the name = "1", we don't find it(classpath:fr/altereo/features/addon/commons/model/commons.baseentity.softdelete.feature:24)
2023-04-29T16:20:27.054+0000 [DEBUG] [TestEventLogger] 
2023-04-29T16:20:27.055+0000 [DEBUG] [TestEventLogger]     org.opentest4j.AssertionFailedError: 
2023-04-29T16:20:27.055+0000 [DEBUG] [TestEventLogger]     expected: 0L
2023-04-29T16:20:27.055+0000 [DEBUG] [TestEventLogger]      but was: 1L
2023-04-29T16:20:27.055+0000 [DEBUG] [TestEventLogger]     	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
2023-04-29T16:20:27.055+0000 [DEBUG] [TestEventLogger]     	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
2023-04-29T16:20:27.055+0000 [DEBUG] [TestEventLogger]     	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
2023-04-29T16:20:27.055+0000 [DEBUG] [TestEventLogger]     	at fr.altereo.features.addon.commons.CommonsBaseEntitySoftDeleteSteps.lEnregistrementNEstPlusTrouvableEnRechercheSimple(CommonsBaseEntitySoftDeleteSteps.kt:95)
2023-04-29T16:20:27.056+0000 [DEBUG] [TestEventLogger]     	at ✽.the soft deletable entity is not findable with select(classpath:fr/altereo/features/addon/commons/model/commons.baseentity.softdelete.feature:31)
2023-04-29T16:20:27.056+0000 [DEBUG] [TestEventLogger] 
2023-04-29T16:20:27.056+0000 [DEBUG] [TestEventLogger]     java.lang.AssertionError: 
2023-04-29T16:20:27.056+0000 [DEBUG] [TestEventLogger]     Expecting empty but was: [fr.altereo.addon.commons.entity.TestBaseEntitySoftDelete-390bb3f0-5cea-cd07-cc5c-7727c7b6c3eb [detached],
2023-04-29T16:20:27.056+0000 [DEBUG] [TestEventLogger]         fr.altereo.addon.commons.entity.TestBaseEntitySoftDelete-139754f9-7047-ab6b-c000-a0eb2b98a206 [detached],
2023-04-29T16:20:27.057+0000 [DEBUG] [TestEventLogger]         fr.altereo.addon.commons.entity.TestBaseEntitySoftDelete-e79729ad-0a88-6212-2347-87aa4f4a36a1 [detached]]
2023-04-29T16:20:27.057+0000 [DEBUG] [TestEventLogger]     	at fr.altereo.features.addon.commons.CommonsBaseEntitySoftDeleteSteps.lEntiteAUneCollectionLieeVide(CommonsBaseEntitySoftDeleteSteps.kt:126)
2023-04-29T16:20:27.057+0000 [DEBUG] [TestEventLogger]     	at ✽.the entity has a collection empty(classpath:fr/altereo/features/addon/commons/model/commons.baseentity.softdelete.feature:37)

Soft Delete test is in (sample-commons/CommonsBaseEntitySoftDeleteSteps.kt at master · bvopro/sample-commons · GitHub and sample-commons/commons.baseentity.softdelete.feature at master · bvopro/sample-commons · GitHub)

In the commit SomeEntityComment as it should be I remove the fix for the base comment entity where I override fields, the result is a build KO

2023-04-29T16:21:33.870+0000 [DEBUG] [TestEventLogger]             org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.7.9.6-jmix): org.eclipse.persistence.exceptions.EntityManagerSetupException
2023-04-29T16:21:33.870+0000 [DEBUG] [TestEventLogger]             Exception Description: Deployment of PersistenceUnit [main] failed. Close all factories for this PersistenceUnit.
2023-04-29T16:21:33.870+0000 [DEBUG] [TestEventLogger]             Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.7.9.6-jmix): org.eclipse.persistence.exceptions.IntegrityException
2023-04-29T16:21:33.870+0000 [DEBUG] [TestEventLogger]             Descriptor Exceptions: 
2023-04-29T16:21:33.870+0000 [DEBUG] [TestEventLogger]             ---------------------------------------------------------
2023-04-29T16:21:33.871+0000 [DEBUG] [TestEventLogger] 
2023-04-29T16:21:33.871+0000 [DEBUG] [TestEventLogger]             Exception [EclipseLink-60] (Eclipse Persistence Services - 2.7.9.6-jmix): org.eclipse.persistence.exceptions.DescriptorException
2023-04-29T16:21:33.871+0000 [DEBUG] [TestEventLogger]             Exception Description: The method [_persistence_set_user_vh] or [_persistence_get_user_vh] is not defined in the object [fr.altereo.addon.commons.entity.SomeEntityComment].
2023-04-29T16:21:33.871+0000 [DEBUG] [TestEventLogger]             Internal Exception: java.lang.NoSuchMethodException: fr.altereo.addon.commons.entity.SomeEntityComment._persistence_get_user_vh()
2023-04-29T16:21:33.871+0000 [DEBUG] [TestEventLogger]             Mapping: org.eclipse.persistence.mappings.ManyToOneMapping[user]
2023-04-29T16:21:33.871+0000 [DEBUG] [TestEventLogger]             Descriptor: RelationalDescriptor(fr.altereo.addon.commons.entity.SomeEntityComment --> [DatabaseTable(COM_SOME_ENTITY_COMMENT)])
2023-04-29T16:21:33.871+0000 [DEBUG] [TestEventLogger] 
2023-04-29T16:21:33.871+0000 [DEBUG] [TestEventLogger]             Exception [EclipseLink-218] (Eclipse Persistence Services - 2.7.9.6-jmix): org.eclipse.persistence.exceptions.DescriptorException
2023-04-29T16:21:33.871+0000 [DEBUG] [TestEventLogger]             Exception Description: A NullPointerException would have occurred accessing a non-existent weaved _vh_ method [_persistence_get_user_vh].  The class was not weaved properly - for EE deployments, check the module order in the application.xml deployment descriptor and verify that the module containing the persistence unit is ahead of any other module that uses it.

Comments test is in (sample-commons/CommonsWithCommentsStepdefs.kt at master · bvopro/sample-commons · GitHub and sample-commons/commons.comments.feature at master · bvopro/sample-commons · GitHub)

I hope that will be suffisant to you to resolve my problems

Hello, @b.vallettedosia

Thank you for the English version of the project code!

Both problems were caused by an old eclipselink bug:
@MappedSuperclass is not weaved properly when it has no inheritors which happens for BaseEntitySoftDelete and BaseComment
They had a similar problem earlier and fixed it. Unfortunately, not all mechanisms have been fixed (e.g. valueholders).

As a workaround, you can add dummy entities to addon-commons module
Inheritance_bugs_workaround.patch.txt (2.0 KB)

We have an issue to investigate the problem more closely.

Regards,
Dmitry

1 Like