bug:node to traverse cannot be null! 的错误分析

本文针对Hibernate框架中出现的nodetotraversecannotbenull异常进行了详细的解析,并提供了具体的解决方案,强调了HQL拼接时应注意的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一,问题描述: 

异常:node to traverse cannot be null!

 

	@Override
	public Collection<T> getAllEntry() {
		// TODO Auto-generated method stub
		return this.getHibernateTemplate().find("from "+this.classt.getName());
	}

        @Override
	public Collection<T> getAllEntry() {
		// TODO Auto-generated method stub
		return this.getHibernateTemplate().find("from "+this.classt.getName());
	}

 二,解决办法

   关于这个访问action的错误 请注意hql是否拼接错误。

HQL = “from entry”  注意拼接时from后面跟上空格。很小的错误新手很难找。
<template> <div> <div id="container" style="width:100%; height: 600px;"></div> <!-- 添加节点的对话框 --> <el-dialog v-model="dialogVisible" title="添加新节点" width="30%"> <el-input v-model="newNodeName" placeholder="请输入节点名称" /> <div style="margin-top: 20px;"> <span style="margin-right: 10px;">选择类型:</span> <el-select v-model="proxyType"> <el-option label="Proxy" value="proxy" /> <el-option label="Global" value="global" /> </el-select> </div> <template #footer> <el-button @click="dialogVisible = false">取消</el-button> <el-button type="primary" @click="hildNode">确认</el-button> </template> </el-dialog> </div> </template> <script setup> import { ref, onMounted } from 'vue'; import { Graph,treeToGraphData,register,ExtensionCategory } from '@antv/g6'; import {TREELIST} from './data' import networkimg from "@/assets/img/network.png" import proxy from "@/assets/img/proxy.png" const rawData = ref(TREELIST) let dialogVisible =ref(false) let newNodeName =ref('') let parentId = ref('') let isConfirm=ref(false) const graphRef = ref(null); // 新增 ref 存储 graph 实例 let ss=ref() onMounted(() => { const container = document.getElementById('container'); function isLeafNode(d) { return !d.children || d.children.length === 0; } const graph = new Graph({ container: 'container', autoFit: 'view', data: treeToGraphData(rawData.value), behaviors: ['drag-canvas', 'zoom-canvas', 'drag-element', 'collapse-expand'], node: { type: 'image', style: (d) => { let imgUrl; if (d.depth === 0) { // 第二层(根节点深度0,其子节点深度1) imgUrl = networkimg; } else { imgUrl = proxy; // 其他节点使用原来的逻辑(根据类型等) } const style = { src: imgUrl, labelText: d.id, labelPlacement: 'right', labelBackground: true, ports: [{ placement: 'top' }, { placement: 'bottom' }], }; if (isLeafNode(d)) { Object.assign(style, { labelTransform: [ ['rotate', 90], ['translate', 18], ], labelBaseline: 'center', labelTextAlign: 'left', }); } return style; }, animation: { enter: false, }, }, edge: { type: 'cubic-vertical', animation: { enter: false, }, }, layout: { preventOverlap: true, type: 'compact-box', direction: 'TB', getHeight: function getHeight() { return 16; }, getWidth: function getWidth() { return 16; }, getVGap: function getVGap() { return 80; }, getHGap: function getHGap() { return 20; }, }, plugins: [ { type: 'contextmenu', trigger: 'click', // 'click' or 'contextmenu' onClick: (value, target, current) => { // alert('You have clicked the「' + value + '」item'); if(value == 'add'){ parentId.value = current.id dialogVisible.value=true // if (parentId.value) { // console.log(isConfirm.value,"ff") // if(isConfirm.value == true){ // addChildNode(parentId.value, graph) // } // } }else{ deleteNode(current.id, graph) } }, getItems: () => { return [ { name: '添加节点', value: 'add' }, { name: '删除', value: 'delete' }, ]; }, // enable: (e) => e.targetType === 'node', }, ], }); graphRef.value = graph; graph.render(); }); const hildNode = () => { // if (!graphRef.value) return; // 防止未初始化访问 addChildNode(parentId.value, graphRef.value); // 使用 ref.value 获取 graph 实例 dialogVisible.value = false; }; function addChildNode(parentId, graphInstance) { const newNode = {id: `node-${Date.now()}`} // 需要确保rawData是响应式数据 const currentData = rawData.value // 深拷贝原始数据 const traverse = (node) => { if (node.id === parentId) { if (!node.children) node.children = [] node.children.push(newNode) return true } return node.children?.some(child => traverse(child)) } if (traverse(currentData)) { rawData.value = currentData // 更新图形数据 graphInstance.setData(treeToGraphData(rawData.value)) // graphInstance.layout(true) graphInstance.fitView() graphInstance.render() // 确保重新渲染 } } function deleteNode(nodeId, graphInstance) { // 特殊情况处理:不允许删除根节点 if (nodeId === rawData.value.id) { alert('Cannot delete root node!') return } // 深拷贝原始数据以避免直接修改响应式数据 const currentData = rawData.value // 递归查找并删除目标节点 const traverse = (node) => { if (node.children) { const index = node.children.findIndex(child => child.id === nodeId) if (index !== -1) { node.children.splice(index, 1) return true } return node.children.some(child => traverse(child)) } return false } if (traverse(currentData)) { // 更新原始数据 rawData.value = currentData // 更新图形数据 graphInstance.setData(treeToGraphData(currentData)) graphInstance.fitView() graphInstance.render() } } const getNodeImage = (d) => { // 根据节点类型返回不同的图片URL // 你可以根据实际情况调整这里的逻辑 if (d.type === 'web') return 'https://gw.alipayobjects.com/zos/basement_prod/2741e936-104b-492e-84e4-93c06f7d8718.svg '; if (d.type === 'database') return 'https://gw.alipayobjects.com/zos/basement_prod/36d682d1-577a-4695-8757-7989473f5526.svg '; // if (isLeafNode(d)) return 'https://gw.alipayobjects.com/zos/basement_prod/5e9283de-89e3-476d-98e3-229933c804a5.svg '; return 'https://gw.alipayobjects.com/zos/basement_prod/5e9283de-89e3-476d-98e3-229933c804a5.svg '; // 默认图片 }; </script> 添加完第一个浏览器就假死了
最新发布
07-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值