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

fix test when nested jpaDerivedIdentifier is used #18067

Merged
merged 6 commits into from
Mar 18, 2022

Conversation

emilpaw
Copy link
Contributor

@emilpaw emilpaw commented Mar 8, 2022

when a relationship is used with the jpaDerivedIdentifier option and the
related entity also has a relationship with that option set the
updateEntityMapsIdAssociationWithNewId test fails. This
is caused by the createUpdatedEntity reusing the needed parent
entity. This can't work because a parent entity, which already has a child,
can't be used as the parent for a new entity. The reason being
jpaDerivedIdentifier enforces that parent and child share the same id,
which can't be fulfilled with a reused parent entity.
Remove the reuse of the parent entity in createUpdatedEntity when the
entity uses jpaDerivedIdentifier to fix the test.

Fixes #17906


Please make sure the below checklist is followed for Pull Requests.

When you are still working on the PR, consider converting it to Draft (below reviewers) and adding skip-ci label, you can still see CI build result at your branch.

@emilpaw emilpaw changed the title fix test when nested derived jpaDerivedIdentifier is used fix test when nested jpaDerivedIdentifier is used Mar 8, 2022
@emilpaw emilpaw force-pushed the nested-derived-identifier-failing-tests branch from 6cc8d17 to 08ee70c Compare March 9, 2022 10:16
@emilpaw
Copy link
Contributor Author

emilpaw commented Mar 9, 2022

The failing test react-gradle-mysql-es-noi18n-mapsid has nothing to do with my change. I wonder why this test hasn't failed before since I did not introduce the issue.

Either way, I'd like to add a test for the changes I made but I haven't figured out where exactly it should be placed. Could someone help me with that?

@emilpaw emilpaw force-pushed the nested-derived-identifier-failing-tests branch from 08ee70c to fa67538 Compare March 10, 2022 20:31
@mraible
Copy link
Contributor

mraible commented Mar 13, 2022

Tests pass. Is this good enough?

@emilpaw
Copy link
Contributor Author

emilpaw commented Mar 13, 2022

@mraible The existing tests never caught the issue this PR fixes. As a measure to avoid regressions, in my opinion, we should add one JDL integration test. I am just still not sure how to go about that.

The JDL I want to test should look something like that:

entity Animal
entity Mamal
entity Cat

relationship OneToOne {
    Mamal to Animal with jpaDerivedIdentifier
    Cat to Mamal with jpaDerivedIdentifier
}

Where should I add such a test case?

@mshima
Copy link
Member

mshima commented Mar 13, 2022

It's possible to add an MapsIdGrandChildEntity*DTO json referring to https://github.com/jhipster/generator-jhipster/blob/2aa6f6d6581f98a8edb08379b252bc20e724b212/test-integration/samples/.jhipster/MapsIdChildEntityWithoutDTO.json

and add here

moveEntity MapsIdChildEntityWithoutDTO

Or add to one of customId samples:

EntityUuidIdMapsId to @Id EntityUuidId

EntityUuidIdDTOMapsId to @Id EntityUuidIdDTO

EntityCustomIdMapsId to @Id EntityCustomId

EntityCustomIdDTOMapsId to @Id EntityCustomIdDTO

@emilpaw
Copy link
Contributor Author

emilpaw commented Mar 13, 2022

@mshima Thank you.

I added the test cases.

@emilpaw emilpaw force-pushed the nested-derived-identifier-failing-tests branch from 66763f2 to 8ce1162 Compare March 13, 2022 23:14
@emilpaw emilpaw marked this pull request as ready for review March 13, 2022 23:14
@emilpaw emilpaw marked this pull request as draft March 15, 2022 08:24
@mshima
Copy link
Member

mshima commented Mar 15, 2022

@emilpaw is this PR ready?

@emilpaw emilpaw marked this pull request as ready for review March 15, 2022 20:27
@emilpaw
Copy link
Contributor Author

emilpaw commented Mar 15, 2022

@mshima Yes, now that the E2E tests are working again it's ready. Thank you for the commit.

Copy link
Member

@mshima mshima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify the condition.

mshima
mshima previously approved these changes Mar 15, 2022
Copy link
Member

@mshima mshima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove back reference, it's not there

"id": true,
"otherEntityField": "id",
"otherEntityName": "mapsIdChildEntityWithDTO",
"otherEntityRelationshipName": "mapsIdGrandchildEntityWithDTO",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"otherEntityRelationshipName": "mapsIdGrandchildEntityWithDTO",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"otherEntityRelationshipName" is needed even if the relationship is unidirectional, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug.
otherEntityRelationshipName should exist only in bidirectional.

@emilpaw emilpaw force-pushed the nested-derived-identifier-failing-tests branch from b699af4 to a813573 Compare March 16, 2022 10:52
when a relationship is used with the jpaDerivedIdentifier option and the
related entity also has a relationship with that option set the
`updateEntityMapsIdAssociationWithNewId` test fails. This
is caused by the `createUpdatedEntity` reusing the needed parent
entity. This can't work because a parent entity, which already has a child,
can't be used as the parent for a new entity. The reason being
jpaDerivedIdentifier enforces that parent and child share the same id,
which can't be fulfilled with a reused parent entity.
Remove the reuse of the parent entity in `createUpdatedEntity` when the
entity uses jpaDerivedIdentifier to fix the test.

Fixes jhipster#17906
@emilpaw emilpaw force-pushed the nested-derived-identifier-failing-tests branch from a813573 to 08e87bd Compare March 16, 2022 10:53
@emilpaw
Copy link
Contributor Author

emilpaw commented Mar 16, 2022

I squashed the commits and now it's ready to merge.

Copy link
Member

@mshima mshima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need investigation if one-to-one works without otherEntity filtering (removes already used ids). But not really related to this PR.

For now, if otherEntityRelationshipName is set, otherEntity is not set and the relationship is id, we should throw. Filtering will not work as expected.

@mshima
Copy link
Member

mshima commented Mar 18, 2022

@emilpaw can you run prettier and add relationships back-reference for the GrandChild?

@emilpaw emilpaw force-pushed the nested-derived-identifier-failing-tests branch from df0b4a4 to bb8e267 Compare March 18, 2022 19:52
@emilpaw
Copy link
Contributor Author

emilpaw commented Mar 18, 2022

@mshima Done.

Copy link
Member

@mshima mshima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mshima mshima merged commit 21a538e into jhipster:main Mar 18, 2022
@emilpaw emilpaw deleted the nested-derived-identifier-failing-tests branch March 18, 2022 21:16
@mshima
Copy link
Member

mshima commented Mar 18, 2022

Thanks @emilpaw

@pascalgrimaud pascalgrimaud added this to the 7.8.0 milestone Mar 27, 2022
@emilpaw
Copy link
Contributor Author

emilpaw commented Dec 22, 2022

Bug bounty claimed: https://opencollective.com/generator-jhipster/expenses/115030 Thanks :)

@DanielFran
Copy link
Member

@emilpaw approved

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

Successfully merging this pull request may close these issues.

Integration tests fail with nested jpaDerivedIdentifier
5 participants