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

EntityView query results in duplicate results #240

Closed
Mobe91 opened this issue Sep 19, 2016 · 1 comment
Closed

EntityView query results in duplicate results #240

Mobe91 opened this issue Sep 19, 2016 · 1 comment
Assignees
Milestone

Comments

@Mobe91
Copy link
Contributor

Mobe91 commented Sep 19, 2016

With approximately the following entity view, the result list contains duplicate DocumentView instances if there is more than 1 workflow entry for a document version.

@EntityView(Document.class)
public abstract class DocumentView {
   @Mapping("currentVersion.workflowEntries")
   public abstract List<WorkflowEntryView> getWorkflowEntries();
}
@beikov beikov added this to the 1.2.0 milestone Oct 11, 2016
@Mobe91
Copy link
Contributor Author

Mobe91 commented Dec 22, 2016

For the record, this is the problematic JPQL query:

SELECT 
d.id AS DocumentView_id, 
currentVersion_1.archivationStatus AS DocumentView_archivationStatus, 
currentVersion_1.cancelled AS DocumentView_cancelled, 
LOWER(COALESCE(NULLIF(COALESCE(localized_language_1.description,localized_d_defaultLanguage_1.description),''),' - ')) AS DocumentView_caseInsensitiveDescription, LOWER(COALESCE(NULLIF(SUBSTRING(COALESCE(localized_language_1.description,localized_d_defaultLanguage_1.description),1,20),''),' - ')) AS DocumentView_caseInsensitiveDescriptionPreview, LOWER(COALESCE(localized_language_1.name,localized_d_defaultLanguage_1.name)) AS DocumentView_caseInsensitiveName, 
(SELECT COUNT(*) FROM Document dSub WHERE dSub.parentDocument.id = d.id AND dSub.deleted = false) AS DocumentView_childCount, 
currentVersion_1.contractDate AS DocumentView_contractDate, 
d.creationDate AS DocumentView_creationDate, 
d.creationUser.id AS DocumentView_creationUser_id, 
CONCAT(creationUser_1.firstname,' ',creationUser_1.lastname) AS DocumentView_creationUser_name, 
d.defaultLanguage AS DocumentView_defaultLanguage, 
COALESCE(NULLIF(COALESCE(localized_language_1.description,localized_d_defaultLanguage_1.description),''),' - ') AS DocumentView_description, COALESCE(NULLIF(SUBSTRING(COALESCE(localized_language_1.description,localized_d_defaultLanguage_1.description),1,20),''),' - ') AS DocumentView_descriptionPreview, COALESCE(localized_language_2.name,localized_documentType_1_defaultLanguage_1.name) AS DocumentView_documentTypeName, 
d.enabled AS DocumentView_enabled, 
CASE WHEN (SELECT COUNT(*) FROM currentVersion_1.templateEntries templateEntry) > 0 THEN true ELSE false END AS DocumentView_hasTemplateEntries, 
CASE WHEN currentVersion_1.validityDate < CURRENT_TIMESTAMP THEN true ELSE false END AS DocumentView_invalid, 
CASE WHEN localized_language_1.name IS NULL THEN false ELSE true END AS DocumentView_isGivenLanguageUsed, 
currentVersion_1.lastCancelDate AS DocumentView_lastCancelDate, 
d.modificationDate AS DocumentView_modificationDate, 
COALESCE(localized_language_1.name,localized_d_defaultLanguage_1.name) AS DocumentView_name, 
(SELECT COUNT(*) FROM d.versions documentVersion) AS DocumentView_numVersions, 
company_1.name AS DocumentView_owner, 
d.ownerUser.id AS DocumentView_ownerUser_id, 
CONCAT(ownerUser_1.firstname,' ',ownerUser_1.lastname) AS DocumentView_ownerUser_name, 
COALESCE(localized_language_3.name,localized_parentDocument_1_defaultLanguage_1.name) AS DocumentView_parentDocumentName, 
CONCAT(party_1.name,' (',partner_1.erpCode,')') AS DocumentView_partner, 
CASE WHEN currentVersion_1.lastCancelDate < CURRENT_TIMESTAMP THEN true ELSE false END AS DocumentView_uncancelable, 
CASE WHEN localized_language_1.name IS NULL THEN d.defaultLanguage ELSE :language END AS DocumentView_usedLanguage, 
currentVersion_1.validityDate AS DocumentView_validityDate, 
workflowEntries_1.id AS DocumentView_workflowEntries_id, 
workflowEntries_1.creationDate AS DocumentView_workflowEntries_creationDate, 
workflowEntries_1.status AS DocumentView_workflowEntries_status, 
workflowEntries_1.uniqueId AS DocumentView_workflowEntries_uniqueId, 
workflowEntries_1.workflow.id AS DocumentView_workflowEntries_workflow_id, 
workflow_1.defaultLanguage AS DocumentView_workflowEntries_workflow_defaultLanguage, 
COALESCE(NULLIF(COALESCE(localized_language_4.description,localized_workflow_1_defaultLanguage_1.description),''),' - ') AS DocumentView_workflowEntries_workflow_description, COALESCE(NULLIF(SUBSTRING(COALESCE(localized_language_4.description,localized_workflow_1_defaultLanguage_1.description),1,20),''),' - ') AS DocumentView_workflowEntries_workflow_descriptionPreview, 
CASE WHEN localized_language_4.name IS NULL THEN false ELSE true END AS DocumentView_workflowEntries_workflow_isGivenLanguageUsed, 
COALESCE(localized_language_4.name,localized_workflow_1_defaultLanguage_1.name) AS DocumentView_workflowEntries_workflow_name, 
CASE WHEN localized_language_4.name IS NULL THEN workflow_1.defaultLanguage ELSE :language END AS DocumentView_workflowEntries_workflow_usedLanguage, 
currentVersion_1.validityDate AS DocumentView_$0, 
d.validityNotificationLeadTime AS DocumentView_$1, 
currentVersion_1.lastCancelDate AS DocumentView_$2, 
d.lastCancelNotificationLeadTime AS DocumentView_$3, 
currentVersion_1.fileReferenceData AS DocumentView_$4, 
NULLIF(1,1), 
NULLIF(1,1), 
NULLIF(1,1), 
owner_1.id AS DocumentView_$8, 
currentVersion_1.id AS DocumentView_$9 

FROM Document d 
JOIN d.creationUser creationUser_1 
LEFT JOIN d.currentVersion currentVersion_1 
LEFT JOIN currentVersion_1.workflowEntries workflowEntries_1 
LEFT JOIN workflowEntries_1.workflow workflow_1 
LEFT JOIN workflow_1.localized localized_language_4 ON KEY(localized_language_4) = :language 
LEFT JOIN workflow_1.localized localized_workflow_1_defaultLanguage_1 ON KEY(localized_workflow_1_defaultLanguage_1) = workflow_1.defaultLanguage 
JOIN d.documentType documentType_1 
LEFT JOIN documentType_1.localized localized_documentType_1_defaultLanguage_1 ON KEY(localized_documentType_1_defaultLanguage_1) = documentType_1.defaultLanguage 
LEFT JOIN documentType_1.localized localized_language_2 ON KEY(localized_language_2) = :language 
LEFT JOIN d.localized localized_d_defaultLanguage_1 ON KEY(localized_d_defaultLanguage_1) = d.defaultLanguage 
LEFT JOIN d.localized localized_language_1 ON KEY(localized_language_1) = :language 
JOIN d.owner owner_1 JOIN owner_1.company company_1 
JOIN d.ownerUser ownerUser_1 
LEFT JOIN d.parentDocument parentDocument_1 
LEFT JOIN parentDocument_1.localized localized_language_3 ON KEY(localized_language_3) = :language 
LEFT JOIN parentDocument_1.localized localized_parentDocument_1_defaultLanguage_1 ON KEY(localized_parentDocument_1_defaultLanguage_1) = parentDocument_1.defaultLanguage 
JOIN d.partner partner_1 
LEFT JOIN partner_1.party party_1 

WHERE d.id IN (:param_0) ORDER BY CASE WHEN d.id = 100000020 THEN 0 WHEN d.id = 100000002 THEN 1 WHEN d.id = 100000001 THEN 2 WHEN d.id = 100000000 THEN 3 ELSE 4 END ASC NULLS LAST, CASE WHEN workflowEntries_1.creationDate IS NULL THEN 1 ELSE 0 END, DocumentView_workflowEntries_creationDate DESC

Mobe91 added a commit that referenced this issue Dec 23, 2016
@beikov beikov self-assigned this Dec 29, 2016
@beikov beikov closed this as completed in 75a1819 Jan 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants