Struts Problem Report
Struts has detected an unhandled exception:
Messages:
- identifier of an instance of cn.itcast.elec.domain.ElecApplication was altered from 1 to null
File:
org/hibernate/event/def/DefaultFlushEntityEventListener.java
Line number:
85
Stacktraces
org.hibernate.HibernateException: identifier of an instance of cn.itcast.elec.domain.ElecApplication was altered from 1 to null
错误信息: 某个对象的主键被置空!
总结:由于使用BeanUtils.copyProperties()方法copy两个对象;错误发现了:
我到错了包,正确的 import com.sun.org.apache.commons.beanutils.BeanUtils;
第一参数是: 需要复制的对象
第二参数哦:是被复制的对象
@Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
public void saveApplication(ElecApplication elecApplication) {
Integer applicationIds = elecApplication.getApplicationTemplateID();
/* 获取模板对象* */
ElecApplicationTemplate elecApplicationTemplate = elecApplicationTemplateDao
.findObjectByID(applicationIds);
/** 保存申请信息 */
this.saveElecApplication(elecApplication,elecApplicationTemplate);
// 从模板中得到key
String key = elecApplicationTemplate.getProcessDefinitionKey();
/** 启动线程定义 */
Map<String, Object> variables = new HashMap<String, Object>();
ProcessVariables processVariables = this.applicationToProcessVariables(elecApplication);
// javaBean复制
variables.put("application", processVariables);
ProcessInstance pi = processEngine.getExecutionService()
.startProcessInstanceByKey(key, variables);
// 获取任务id
Task task = processEngine.getTaskService()//
.createTaskQuery()//
.processInstanceId(pi.getId())// 使用流程实例的ID进行查询
.uniqueResult();
/** 完成任务 */
processEngine.getTaskService().completeTask(task.getId());
}
/* javaBean的复制* */
private ProcessVariables applicationToProcessVariables(
ElecApplication elecApplication) {
//如果2个对象中的属性相同,类型相同,可以完成值的复制
ProcessVariables processVariables = new ProcessVariables();
try {
BeanUtils.copyProperties(processVariables, elecApplication);
} catch (Exception e) {
throw new RuntimeException();
}
return processVariables;
}
// 保存申请信息;
private void saveElecApplication(ElecApplication elecApplication,
ElecApplicationTemplate elecApplicationTemplate) {
/* 获取模板名称* */
String templateName = elecApplicationTemplate.getName();
/* 从session中获得申请人的名称* */
ElecUser elecUser = (ElecUser) ServletActionContext.getRequest()
.getSession().getAttribute("globle_user");
String applicationName = elecUser.getUserName();
/* 获取当前时间转化为String* */
Date date = new Date();
String dateTimeString = DateToStringUtils.currentDateToString(date);
/* 创建申请信息对象* */
elecApplication.setTitle(templateName + applicationName + dateTimeString);
elecApplication.setApplyTime(new Date());
elecApplication.setStatus(ElecApplication.APPLICATION_RUNNING);
elecApplication.setElecApplicationTemplate(elecApplicationTemplate);
elecApplication.setElecUser(elecUser);
/* 获取文件上传路径* */
File upload = elecApplication.getUpload();
String path = FileUploadUtils.fileReturnPath(upload);
elecApplication.setPath(path);
/** 保存当前信息 */
elecApplicationDao.save(elecApplication);
}
相关推荐
标题“Single Instance of an Application Class (21KB)”和描述中的信息表明,这是一个关于如何确保应用程序仅有一个实例运行的技术主题。在计算机编程中,特别是Windows桌面应用开发中,"单例应用"是一种设计模式...
在编程领域,尤其是在面向对象编程(OOP)中,"Instance of Subclass" 和 "Instance of Superclass" 是两个核心概念,它们与继承、多态等特性紧密相关。"Subclass"(子类)和 "Superclass"(超类或父类)是描述类...
"java-multicast-instance.rar"是一个关于Java实现组播功能的实例压缩包,包含了一个具体的编程示例,可以帮助开发者更好地理解和应用Java的组播技术。 在Java中,实现组播功能主要依赖于`java.net.MulticastSocket...
《飞思卡尔功率管MRF8P9040N技术详解》 在电子工程领域,功率管是不可或缺的一部分,特别是在电源管理、电机控制、功率转换等应用中。飞思卡尔,作为全球知名的半导体公司,提供了众多高性能的功率器件,其中MRF8P...
这个名为"Java_program_instance.rar"的压缩包文件显然包含了一个关于Java游戏程序设计的实例教程,特别关注Java绘图和游戏设计的基础知识。以下是基于这些信息的详细知识点解释: 1. **Java游戏编程基础**: Java...
Java单例模式是一种常见的设计模式,它在软件工程中被广泛使用,以确保一个类只有一个实例,并提供一个全局访问点。这种模式对于那些资源管理、配置对象或日志记录等需要全局唯一的对象非常有用。在Java中实现单例...
Java 中 new 关键字和 newInstance() 的区分 Java 中的 new 关键字和 newInstance() 方法都是用于创建对象的,但是它们之间有着本质的区别。理解这两者的区别对于 Java 编程尤其重要。 首先,new 关键字是 Java 的...
Creates an instance of several families of classes Builder Separates object construction from its representation Factory Method Creates an instance of several derived classes Prototype A fully ...
在"java_array_instance.rar_This Is It"这个示例中,可能包含了多种数组实例化的例子,如一维数组、二维数组,甚至可能是自定义对象的数组。文件`www.pudn.com.txt`可能包含了相关代码的详细解释,而`java`文件可能...
We observe that analysts of such applications often want to do more than analyze a specific instance of the application’s pro- cess control and database. In particular they want to in- teractively ...
The MINNs perform MIL in an end-to-end manner, which take bags with a various number of instances as input and directly output the labels of bags. All of the parameters in a MINN can be optimized via...
NX二次开发UF_ASSEM_ask_parent_of_instance 函数介绍,Ufun提供了一系列丰富的 API 函数,可以帮助用户实现自动化、定制化和扩展 NX 软件的功能。无论您是从事机械设计、制造、模具设计、逆向工程、CAE 分析等领域...
NX二次开发UF_ASSEM_ask_child_of_instance 函数介绍,Ufun提供了一系列丰富的 API 函数,可以帮助用户实现自动化、定制化和扩展 NX 软件的功能。无论您是从事机械设计、制造、模具设计、逆向工程、CAE 分析等领域的...
NX二次开发UF_ASSEM_ask_stable_id_of_instance 函数介绍,Ufun提供了一系列丰富的 API 函数,可以帮助用户实现自动化、定制化和扩展 NX 软件的功能。无论您是从事机械设计、制造、模具设计、逆向工程、CAE 分析等...
OLAPCell The OLAPCell class represents a cell in an OLAPResult instance. OLAPCube The OLAPCube class represents an OLAP cube. OLAPDimension The OLAPDimension class represents a dimension of an OLAP...
* This static method create an instance of the ExceptionManager by invoking the * constructor <code>ExceptionManager(String msg)</code>. * * @param msg The message will pass the specified ...
included with the 1.2.1 version of the Java 2 Platform, Enterprise Edition (J2EE), so it is still commonly used. The version of the JavaMail API you want to use affects what you download and install...
在Java编程语言中,"实例"(Instance)通常指的是一个类的具体对象。当我们谈论"JAVA源码"时,这是指用Java编写的程序代码,它包含了类定义、方法实现、变量声明等元素,是我们理解和创建应用程序的基础。在这个...
instance-level 3D scene understanding. We train a deep convolutional network that learns to map image regions to the full 3D shape and pose of all object instances in the image. Our method produces a ...