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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const otherEntities = _.uniq(Object.values(differentRelationships).filter(rels =
const skipCreateTest =
(
!cypressBootstrapEntities ||
requiredRelationships.some(rel => rel.otherEntity.primaryKey && rel.otherEntity.primaryKey.derived) ||
requiredRelationships.some(rel => rel.otherEntity.builtInUser || rel.otherEntity === this.entity) ||
requiredRelationships.map(rel => rel.otherEntity.relationships).flat().some(rel => rel.relationshipRequired) ||
!entityFakeData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,17 @@ if (field.fieldTypeString || field.blobContentTypeText) {
<%_ } else { _%>
<%= asEntity(otherEntityNameCapitalized) %> <%= otherEntityName %>;
<%_ if (databaseTypeSql && !reactive) { _%>
<%_ if (!isUsingMapsId || fieldStatus !== "UPDATED_") { _%>
if (TestUtil.findAll(em, <%= asEntity(otherEntityNameCapitalized) %>.class).isEmpty()) {
<%_ } _%>
<%= otherEntityName %> = <%= createEntityPrefix %><%= otherEntityNameCapitalized %>ResourceIT.create<% if (fieldStatus === 'UPDATED_') { %>Updated<% } %>Entity(em)<%= createEntityPostfix %>;
em.persist(<%= otherEntityName %>);
em.flush();
<%_ if (!isUsingMapsId || fieldStatus !== "UPDATED_") { _%>
} else {
<%= otherEntityName %> = TestUtil.findAll(em, <%= asEntity(otherEntityNameCapitalized) %>.class).get(0);
}
<%_ } _%>
<%_ } else { _%>
<%= otherEntityName %> = <%= createEntityPrefix %><%= otherEntityNameCapitalized %>ResourceIT.create<% if (fieldStatus === 'UPDATED_') { %>Updated<% } %>Entity(<% if (databaseType === 'sql') { %>em<% } %>)<%= createEntityPostfix %>;
<%_ } _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"clientRootFolder": "",
"databaseType": "sql",
"dto": "mapstruct",
"entityTableName": "maps_id_child_entity_withdto",
"entityTableName": "maps_id_child_with_dto",
"fields": [{ "fieldName": "date", "fieldType": "Instant" }],
"fluentMethods": true,
"jpaMetamodelFiltering": false,
Expand All @@ -17,6 +17,13 @@
"ownerSide": true,
"relationshipName": "mapsIdParentEntityWithDTO",
"relationshipType": "one-to-one"
},
{
"otherEntityName": "mapsIdGrandchildEntityWithDTO",
"otherEntityRelationshipName": "mapsIdChildEntityWithDTO",
"ownerSide": false,
"relationshipName": "mapsIdGrandchildEntityWithDTO",
"relationshipType": "one-to-one"
}
],
"searchEngine": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"clientRootFolder": "",
"databaseType": "sql",
"dto": "no",
"entityTableName": "child_entity_wo_dto",
"entityTableName": "maps_id_child_wo_dto",
"fields": [{ "fieldName": "date", "fieldType": "Instant" }],
"fluentMethods": true,
"jpaMetamodelFiltering": false,
Expand All @@ -17,6 +17,13 @@
"ownerSide": true,
"relationshipName": "mapsIdParentEntityWithoutDTO",
"relationshipType": "one-to-one"
},
{
"otherEntityName": "mapsIdGrandchildEntityWithoutDTO",
"otherEntityRelationshipName": "mapsIdChildEntityWithoutDTO",
"ownerSide": false,
"relationshipName": "mapsIdGrandchildEntityWithoutDTO",
"relationshipType": "one-to-one"
}
],
"searchEngine": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"changelogDate": "20220313234025",
"clientRootFolder": "",
"databaseType": "sql",
"dto": "mapstruct",
"entityTableName": "maps_id_grandchild_with_dto",
"fields": [{ "fieldName": "date", "fieldType": "Instant" }],
"fluentMethods": true,
"jpaMetamodelFiltering": false,
"pagination": "no",
"relationships": [
{
"id": true,
"otherEntityField": "id",
"otherEntityName": "mapsIdChildEntityWithDTO",
"otherEntityRelationshipName": "mapsIdGrandchildEntityWithDTO",
mshima marked this conversation as resolved.
Show resolved Hide resolved
"ownerSide": true,
"relationshipName": "mapsIdChildEntityWithDTO",
"relationshipType": "one-to-one"
}
],
"searchEngine": false,
"service": "serviceImpl"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"changelogDate": "20220313234416",
"clientRootFolder": "",
"databaseType": "sql",
"dto": "no",
"entityTableName": "maps_id_grandchild_wo_dto",
"fields": [{ "fieldName": "date", "fieldType": "Instant" }],
"fluentMethods": true,
"jpaMetamodelFiltering": false,
"pagination": "no",
"relationships": [
{
"id": true,
"otherEntityField": "id",
"otherEntityName": "mapsIdChildEntityWithoutDTO",
"otherEntityRelationshipName": "mapsIdGrandchildEntityWithoutDTO",
"ownerSide": true,
"relationshipName": "mapsIdChildEntityWithoutDTO",
"relationshipType": "one-to-one"
}
],
"searchEngine": false,
"service": "no"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"clientRootFolder": "",
"databaseType": "sql",
"dto": "mapstruct",
"entityTableName": "maps_id_parent_entity_withdto",
"entityTableName": "maps_id_parent_with_dto",
"fields": [{ "fieldName": "name", "fieldType": "String" }],
"fluentMethods": true,
"jpaMetamodelFiltering": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"clientRootFolder": "",
"databaseType": "sql",
"dto": "no",
"entityTableName": "parent_entity_wo_dto",
"entityTableName": "maps_id_parent_wo_dto",
"fields": [{ "fieldName": "name", "fieldType": "String" }],
"fluentMethods": true,
"jpaMetamodelFiltering": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"clientRootFolder": "",
"databaseType": "sql",
"dto": "mapstruct",
"entityTableName": "maps_id_user_profile_withdto",
"entityTableName": "maps_id_user_profile_with_dto",
"fields": [{ "fieldName": "dateOfBirth", "fieldType": "Instant" }],
"fluentMethods": true,
"jpaMetamodelFiltering": false,
Expand Down
2 changes: 2 additions & 0 deletions test-integration/scripts/11-generate-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ elif [[ "$JHI_ENTITY" == "sqlfull" ]]; then

moveEntity MapsIdParentEntityWithoutDTO
moveEntity MapsIdChildEntityWithoutDTO
moveEntity MapsIdGrandchildEntityWithoutDTO
moveEntity MapsIdParentEntityWithDTO
moveEntity MapsIdChildEntityWithDTO
moveEntity MapsIdGrandchildEntityWithDTO
moveEntity MapsIdUserProfileWithDTO

moveEntity JpaFilteringRelationship
Expand Down
2 changes: 2 additions & 0 deletions test-integration/scripts/11-generate-entities.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ elif [[ "$JHI_ENTITY" == "sqlfull" ]]; then

moveEntity MapsIdParentEntityWithoutDTO
moveEntity MapsIdChildEntityWithoutDTO
moveEntity MapsIdGrandchildEntityWithoutDTO
moveEntity MapsIdParentEntityWithDTO
moveEntity MapsIdChildEntityWithDTO
moveEntity MapsIdGrandchildEntityWithDTO
moveEntity MapsIdUserProfileWithDTO

moveEntity JpaFilteringRelationship
Expand Down
7 changes: 6 additions & 1 deletion utils/relationship.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ function prepareRelationshipForTemplates(entityWithConfig, relationship, generat
}
return otherSideRelationship.relationshipName === relationship.otherEntityRelationshipName;
});
if (
if (!otherRelationship) {
// TODO throw error at v8.
generator.warning(
`Error at '${entityName}' definitions: 'otherEntityRelationshipName' is set with value '${relationship.otherEntityRelationshipName}' at relationship '${relationship.relationshipName}' but no back-reference was found at '${otherEntityName}'`
);
} else if (
otherRelationship &&
otherRelationship.otherEntityRelationshipName &&
otherRelationship.otherEntityRelationshipName !== relationship.relationshipName
Expand Down