最近开发和学习过程中,遇到很多零碎的知识点,在此简单地记录下:

1.遇如下bug:

org.unsaved transient instance - save the transient instance before flushing: org.blog.blog.domain.HighStudent

解释:意思是说hibernate从数据库中查询出来的一个对象HighSchool(为持态,我给它的事物定义为readOnly,只有只读权限),然后又给它的属性或者它属性的属性(highStudents.comment.cxpy)进行set值,这样hibernate是不允许的。因为你对一个事物为只读状态的对象进行赋值,显然是不允许,除非你主动调用saveOrUpate

方法。serice方法事物是readOnly,dao中就查询出来的对象不允许修改属性。

解决方法:将查询出来的对像使用session.evict()方法转换为游离态,此时就可以查询成功。代码如下:

@Override
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public List<PrimaryStudents> getPrimaryStudentsList(String[] stuids)
throws StuBaseDataException {
List<PrimaryStudents> list=new ArrayList<PrimaryStudents>();
String stu=stuids[0];
String [] studentids=stu.split(",");
System.out.println(studentids.length);
try{
if(studentids.length>0){
for(int i=0;i<studentids.length ;i++){
PrimaryStudents primaryStudents=null;
primaryStudents=this.primaryStudentsDao.queryPrimaryStudentsBystuid(studentids[i]);
if(primaryStudents==null){
throw new StuBaseDataException("该批学生中存在学生信息不存在的学生,请刷新之后再进行该操作");
}
list.add(primaryStudents);
}
}else{
throw new StuBaseDataException("请选择一位学生");
}
}catch (Exception e) {
e.printStackTrace();
throw new StuBaseDataException("查询失败!!!",e);
}
return list;
}
    @Override
public PrimaryStudents queryPrimaryStudentsBystuid(String stuid) {
List<PrimaryStudents> list= null;
Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
String sql="From PrimaryStudents ps where ps.id in("+stuid+")";
Query query = session.createQuery(sql);
list = query.list();
if (list != null && list.size() > 0)
{
/**
* 在做学籍卡批量打印的时候,显示问题。
* 评语不足6个的时候,构造几个空的,显示到页面上去。
* 强制转换为游离态
*/
session.evict(list.get(0));
return (PrimaryStudents)list.get(0);
}
return null;
}

org.unsaved transient instance - save the transient instance before flushing: bug解决方案的更多相关文章

  1. ERROR org.hibernate.internal.SessionImpl - HHH000346: Error during managed flush [object references an unsaved transient instance - save the transient instance before flushing: cn.itcast.domain.Custom

    本片博文整理关于Hibernate中级联策略cascade和它导致的异常: Exception in thread "main" org.hibernate.TransientOb ...

  2. object references an unsaved transient instance save the transient instance before flushing

    object references an unsaved transient instance save the transient instance before flushing 对象引用未保存的 ...

  3. object references an unsaved transient instance - save the transient instance before flushing: com.jspxcms.core.domain.ScTeam

    object references an unsaved transient instance - save the transient instance before flushing: com.j ...

  4. object references an unsaved transient instance - save the transient instance before flushing异常问题处理

    一.异常:org.hibernate.TransientObjectException: object references an unsaved transient instance - save ...

  5. object references an unsaved transient instance - save the transient instance before flushing错误

    异常1:not-null property references a null or transient value解决方法:将“一对多”关系中的“一”方,not-null设置为false(参考资料: ...

  6. hibernate 对象状态异常:object references an unsaved transient instance - save the transient instance before flushing

    我的问题出在,删除的对象对应的表中有一个外键,关联着另外一个表,可是另外一个表中没有数据,所以报了这个错误. 参考http://www.cnblogs.com/onlywujun/archive/20 ...

  7. Hibernate的一个问题object references an unsaved transient instance - save the transi5

    1 我做了一对多和多对一的双向关联关系,在User这一方@ManyToOne已经设置了级联Cascade,这样在测试程序中保存User时,Group也应该自动保存,为什么会抛出以下的异常: (我是按着 ...

  8. save the transient instance before flushing错误解决办法 【待完善】

    近日在项目中遇到以下错误,着实郁闷了一把: org.hibernate.TransientObjectException: object references an unsaved transient ...

  9. 【总文档】rac增加新节点的方法步骤 How to Add Node/Instance or Remove Node/Instance in 10gR2, 11gR1, 11gR2 and 12c Oracle Clusterware and RAC

    [总文档]How to Add Node/Instance or Remove Node/Instance in 10gR2, 11gR1, 11gR2 and 12c Oracle Clusterw ...

随机推荐

  1. ubuntu common

    系统信息 # uname -a              # 查看内核/操作系统/CPU信息 # cat /etc/issue        # 查看操作系统版本 #cat /proc/version ...

  2. 图像分类之特征学习ECCV-2010 Tutorial: Feature Learning for Image Classification

    ECCV-2010 Tutorial: Feature Learning for Image Classification Organizers Kai Yu (NEC Laboratories Am ...

  3. gearman安装及初次使用

    官网:  http://gearman.org/ 一篇文章: 利用Gearman实现异步任务处理 一.问题分析 问题:在性能测试过程中,发现用户管理平台在进行图片上传时,性能不佳. 分析:经过代码分析 ...

  4. Web Server tomcat配置网站

    tomcat配置网站 环境变量: 变量名:CATALINA_HOME 变量值:安装路径 1.在tomcat文件夹的conf"catalina"localhost(对于Tomcat6 ...

  5. iPhone(iOS设备) 无法更新或恢复时, 如何进入恢复模式

    在更新或恢复 iPhone  时,如果遇到以下所列问题之一.可能就要将设备置于恢复模式,并尝试重新恢复设备. 设备不断地重新启动,但从未显示主屏幕. 无法完成更新或恢复,且 iTunes 不再能识别设 ...

  6. Spring高级事务管理难点剖析

    1Spring事务传播行为 所谓事务传播行为就是多个事务方法相互调用时,事务如何在这些方法间传播.Spring支持7种事务传播行为 PROPAGATION_REQUIRED(加入已有事务) 如果当前没 ...

  7. ACdream 1735 输油管道 (排序)

    http://acdream.info/problem?pid=1735 官方题解:http://acdream.info/topic?tid=4246 因为主干线是平行于x轴的直线,那么跟x坐标其实 ...

  8. 总结Selenium自动化测试方法(五)自动化测试框架

    五.自动化测试框架 1.单元测试框架unittest class loginTests(unittest.TestCase): ①开始的初始化部分 @classmethod def setUpClas ...

  9. PhpStorm+PhpStudy+xdebug 配置图解

    1.配置niginx.ini,新增 server节点,比如使用9200 端口 server { listen 9200;#本地调试,不用80端口 server_name localhost; #cha ...

  10. HeadFirst Jsp 14 (Structs)

    大的web程序可能很复杂, 分很多”层” 有关 RMI 的部分, 可以参考 headfirst java 中的 RMI 的部分. struts 是一个框架, 框架是一些接口和类的集合, 这些接口和类设 ...