[ https://issues.apache.org/jira/browse/CAY-2880?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Nikita Timofeev closed CAY-2880. -------------------------------- Assignee: Nikita Timofeev Resolution: Not A Problem > Unable to Set Name for Child Nodes in PrefetchTreeNode > ------------------------------------------------------ > > Key: CAY-2880 > URL: https://issues.apache.org/jira/browse/CAY-2880 > Project: Cayenne > Issue Type: Bug > Components: Core Library > Affects Versions: 4.2.1 > Environment: Windows 11 Java 17 > Reporter: lallemand > Assignee: Nikita Timofeev > Priority: Major > Fix For: 4.2.2 > > > *Description:* > It is currently impossible to use child nodes for {{PrefetchTreeNode}} > because the {{name}} variable cannot be set. This leads to an error when > calling {{{}addChild(){}}}, making the intended functionality unusable. > *Affected Code:* > {code:java} > PrefetchTreeNode prefetchTreeNode = new PrefetchTreeNode(); > // Prefetch 1 > PrefetchTreeNode childPrefetchTreeNode = new PrefetchTreeNode(); > childPrefetchTreeNode.addPath("example.test"); > childPrefetchTreeNode.setSemantics(PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS); > prefetchTreeNode.addChild(childPrefetchTreeNode); > // Prefetch 2 > childPrefetchTreeNode = new PrefetchTreeNode(); > childPrefetchTreeNode.addPath("example.test2"); > childPrefetchTreeNode.setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS); > prefetchTreeNode.addChild(childPrefetchTreeNode); > query.prefetch(prefetchTreeNode); > ObjectContext context = BaseContext.getThreadObjectContext(); > List<?> items = context.performQuery(query); {code} > *Cayenne* {{*addChild*}} *Function:* > {code:java} > public void addChild(PrefetchTreeNode child) { > if (Util.isEmptyString(child.getName())) { > throw new IllegalArgumentException("Child has no segmentPath: " + > child); > } else { > if (child.getParent() != this) { > child.getParent().removeChild(child.getName()); > child.parent = this; > } > if (this.children == null) { > this.children = new ArrayList(4); > } > this.children.add(child); > } > } {code} > *Issue:* > The {{addChild}} function requires the child node to have a name. However: > * The {{PrefetchTreeNode}} constructor that accepts a {{name}} is protected. > * The {{name}} variable itself is protected and cannot be accessed > externally. > * There is no public setter method for {{{}name{}}}. > As a result, it is impossible to set the name of a child node, making the > {{addChild()}} method non-functional for child nodes. > *Workaround:* > None available at this time. > *Suggested Fix:* > * Provide a public constructor that allows setting the {{{}name{}}}. > * Alternatively, add a public setter method for {{name}} to enable proper > initialization of child nodes. -- This message was sent by Atlassian Jira (v8.20.10#820010)