異常處理---01

公司原有的項目我負責的那部份oneToOne oneToMany以及ManyToMany等關係 今天進行聯合查詢時 爆出異常

異常一:failed to lazily initialize a collection of role

原因:

解決方法:

 

網上搜尋了資料  主要是延迟加载搞的鬼,对于一对多的时候最好是

異常二: org.hibernate.LazyInitializationException: could not initialize proxy - no Session

原因是:

 

异常三:a different object with the same identifier value was already associated with the sessionyuang原因: 在session中存在两个对象 关联的同一个标志位,其实这是同一个对象,但自己在做业务操作的时候可能保存了两次,

解决方法

      一是:最笨的方法 是手写HQL 

      二是:调用this.hibernateTemplate.merge();替代his.hibernateTemplate.update()  

 

 

 

 

異常四:Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value

原因: 一個不能為空的屬性引用了一個為空或為無效的值.

       解決方法: 打印將進行操作的對象的各項屬性和值 并檢查各個值是否為空或為無效的值,尤其是對有級聯操作的數據時更要仔細檢查

 

異常五:java.util.NoSuchElementException

原因:  一個迭代器被執行兩次,最好一個為空.

官方的解釋為:

An object of this class is thrown when a collection or iterator is empty. For example, when the next method of an Iterator instance is called when hasNext of that instance returns false as in the code below.

  ArrayList list = new ArrayList();
  list.add(new String("hello"));
  Iterator it = list.iterator();
  System.out.println(it.next());   // ok, list has one element
  System.out.println(it.next());   // NOT ok, iterator is "empty"
 

 修改為:

			for(Ability o: cacheList){
				Iterator<Ability> oldIt = OLDLIST.iterator();
				while(oldIt.hasNext()){
					Ability ability_1 = oldIt.next();
					if(ability_1.getAbilityCode().equals(o.getAbilityCode())){
						System.out.println("----移除OLDLIST共有對象---"+o.getAbilityName());
						oldIt.remove();//先將Iterator移除掉 然後進行數據各項操作
						OLDLIST.remove(ability_1);//移除對象
					}
				}
			}

  又報異常java.util.ConcurrentModificationException

原因為:因為Iterator 有一個独立的线程,并且拥有一个 mutex 锁。當 對Iterator進行迭代式 不能對其內的數據進行刪除和添加操作.否則會報該異常,解決方法是 先把迭代器移除 然後進行數據操作.

官方解解為:

public class ConcurrentModificationException extends RuntimeException

This exception may be thrown by methods that have detected concurrent modification of an object
 when such modification is not permissible.

For example, it is not generally permssible for one thread to modify a Collection while another thread is iterating over it. In general, the results of the iteration are undefined under these 
circumstances. Some Iterator implementations (including those of all the collection implementations 
provided by the JRE) may choose to throw this exception if this behavior is detected. Iterators that 
do this are known as fail-fast iterators, as they fail quickly and cleanly, rather that risking arbitrary, 
non-deterministic behavior at an undetermined time in the future.

Note that this exception does not always indicate that an object has been concurrently modified by 
a different thread. If a single thread issues a sequence of method invocations that violates the 
contract of an object, the object may throw this exception. 
For example, if a thread modifies a collection directly while it is iterating over the collection 
with a fail-fast iterator, the iterator will thow this exception.

Note that fail-fast behavior cannot be guaranteed as it is, generally speaking, 
impossible to make any hard guarantees in the presence of unsynchronized concurrent modification.
 Fail-fast operations throw ConcurrentModificationException on a best-effort basis. Therefore, it 
would be wrong to write a program that depended on this exception for its correctness: 
ConcurrentModificationException should be used only to detect bugs. 

  繼續修改代碼改為:

			for(Ability o: OLDLIST){
				System.out.println("---OLDLIST--"+o.getAbilityName());
				for(Iterator<Ability> newIt= NEWLIST.iterator(); newIt.hasNext();){
					Ability ability_1 = newIt.next();
					if(ability_1.getAbilityCode().equals(o.getAbilityCode())){
						System.out.println("----移除NEWLIST共有對象---"+o.getAbilityName());
						newIt.remove();
						NEWLIST.remove(ability_1);
						cacheList.add(o);
					}
				}
			}

 

  異常五: deleted object would be re-saved by cascade (remove deleted object from associations)

	/**
	 * 所處小組,需要包括管理組
	 * targetEntity 指明相關聯的類為Group.class
	 * FetchType.EAGER 指明預先獲取數據
	 * FetchType.LAZY  延時加載數據
	 * cascade=CascadeType.ALL 表示支持所有的級聯操作
	 * optional = false 表示可允許子集為空
	 * @return group
	 */
	@JsonIgnore
	@ManyToOne(targetEntity=Group.class,cascade=CascadeType.ALL,fetch = FetchType.EAGER)
	@JoinColumn(name="groupID",referencedColumnName="id")
	public Group getGroup() {
		return group;
	}

 異常原因是:

@ManyToOne(targetEntity=Group.class,cascade=CascadeType.ALL,




fetch = FetchType.EAGER)

將其改為:

cascade=CascadeType.REFRESH




就ok了

心得:對於注解掌握的的知識不強!

 

SQL 修改列名和表名

        一: EXEC sp_rename '表名.[列名]' , '新列名' ,'COLUMN'

        二: EXEC sp_rename '表名 ','新表名'.

 

異常六: javax.xml.transform.TransformerConfigurationException: 无法编译样式表

原因有兩種: 一是沒有解析包 可以導入xmlparserv21.jar 或者crimson-1.1.3.jar 等解析.xml和.xsl的jar包

                二是: 文件的路徑或者文件名不正確

 

異常七:javaEE1.5發送郵件時報出異常 Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/QEncoderStream

原因是:jar包之間有衝突,將mail包刪除 或者把換成java1.4EE 的開發環境 就可以在本地測試了.

 

異常八:Eclipse  No embedded stylesheet instruction for file

原因是: 當打開一個xml文件時,單擊Eclipse上的綠色運行按鈕時 拋出異常 并生成一個新的xml文件,解決方法把窗口顯示為你將要運行的java文件,重新運行 就好了! 這可能是Eclipse的一個bug!

 

異常九 spring BeanDefinitionStoreException Caused by: java.net.ConnectExceptio

貌似是網絡原因,其實是 xml文件DTD解析錯誤. 

 

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.5.dtd">
 

改為:

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
 

異常十:javax .mail .MessagingExceptionCould not connect to SMTP hostsmtp .163.comport25

原因 一:本地計算機把端口號25 關閉了,比如一些防護軟件爲了阻止惡意軟件攻擊,會自動關閉端口25

原因二: 163郵箱服務器已關閉該端口

原因三:本地網絡不通.


異常十一:發佈項目是出現異常

 

java.lang.NoClassDefFoundError: 


javax


/el


/


ExpressionFactor









   解決方案: 將 jstl.jar;jsf-impl.jar;javaee.jar;jsf-api.jar 放在tomcat .xx\common\lib文件夾下

 

異常十二:                                   Caused

by: java.lang.IllegalStateException: Neither BindingResult nor plain

target object for bean name 'registrationForm' available as request

attribute


	at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194)
	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:160)
	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:147)
	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:138)
	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:122)
	at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:408)
	at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:140)
	at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
	at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
	at org.apache.jsp.WEB_002dINF.views.registrationform_jsp._jspx_meth_form_005finput_005f0(registrationform_jsp.java:295)
	at org.apache.jsp.WEB_002dINF.views.registrationform_jsp._jspService(registrationform_jsp.java:122)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)

 

異常十三:

java.lang.AbstractMethodError:javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;

org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;
	at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:498)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)

  原因是Tomcat5.x不支持 jstl1.2 一些語法,它只實現了servlet2.4 和jsp2.0的相應規範,tomcat6.x實現了servlet2.5  和jsp2.1相應規範.

兩種解決方法將:

  一:將服務器tomcat5.x 升級為tomcat 6.x

  二:將jstl1.2jar包換成 jstl1.1jar

 

 

 

 

内容概要:本文档详细介绍了一个基于MATLAB实现的跨尺度注意力机制(CSA)结合Transformer编码器的多变量时间序列预测项目。项目旨在精准捕捉多尺度时间序列特征,提升多变量时间序列的预测性能,降低模型计算复杂度与训练时间,增强模型的解释性和可视化能力。通过跨尺度注意力机制,模型可以同时捕获局部细节和全局趋势,显著提升预测精度和泛化能力。文档还探讨了项目面临的挑战,如多尺度特征融合、多变量复杂依赖关系、计算资源瓶颈等问题,并提出了相应的解决方案。此外,项目模型架构包括跨尺度注意力机制模块、Transformer编码器层和输出预测层,文档最后提供了部分MATLAB代码示例。 适合人群:具备一定编程基础,尤其是熟悉MATLAB和深度学习的科研人员、工程师和研究生。 使用场景及目标:①需要处理多变量、多尺度时间序列数据的研究和应用场景,如金融市场分析、气象预测、工业设备监控、交通流量预测等;②希望深入了解跨尺度注意力机制和Transformer编码器在时间序列预测中的应用;③希望通过MATLAB实现高效的多变量时间序列预测模型,提升预测精度和模型解释性。 其他说明:此项目不仅提供了一种新的技术路径来处理复杂的时间序列数据,还推动了多领域多变量时间序列应用的创新。文档中的代码示例和详细的模型描述有助于读者快速理解和复现该项目,促进学术和技术交流。建议读者在实践中结合自己的数据集进行调试和优化,以达到最佳的预测效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值