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

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()方法转换为游离态,此时就可以查询成功。代码如下:

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

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. mars android视频学习笔记一:Activity生命周期

    (1)创建:onCreate->onStart->onResume;(2)失去焦点:onPause->onStop:(3)重新获得焦点:onRestart->onStart-& ...

  2. swift:创建滚动视图的图片轮播器

    用swift创建图片轮播器和用OC创建的方式是一样的,都主要用到UIScrollView和UIImageview这两个控件,有几张图片,就将滚动视图的内容区域大小设置为每一张图片的大小乘以张数即可.然 ...

  3. Android中通过导入静态数据库来提高应用第一次的启动速度

    一个Android应用给用户的第一印象非常重要,除了要有好的创意和美观的界面,性能也是很关键的部分,本文讨论的就是第一次启动的速度问题. Android应用的启动过程不能让用户等待太长时间,个人觉得最 ...

  4. R语言学习笔记——Base Graphics

    做exploratory data annalysis的作业,差点被虐死了,R从头开始,边做边学,最后搞到一点多才弄完,还有一个图怎么画都不对,最后发现是数据读取的时候有问题. 用来画图的数据来自:h ...

  5. uva 10048 Audiophobia(最小生成树)

    题目链接:10048 - Audiophobia 题目大意:有n个城市,和m条街道,每条街道有一个噪音值,q次去问,从城市a到城市b,路径上分贝值的最大值最小为多少. 解题思路:与uva 10099的 ...

  6. ftrace的使用【转】

    转自:http://blog.csdn.net/cybertan/article/details/8258394 This article explains how to set up ftrace ...

  7. js中的编码与解码

    一.encodeURI()定义和用法 encodeURI() 函数可把字符串作为 URI 进行编码. 语法 encodeURI(URIstring) 参数 描述 URIstring 必需.一个字符串, ...

  8. CF 314C Sereja and Subsequences(树状数组)

    题目链接:http://codeforces.com/problemset/problem/314/C 题意:给定一个数列a.(1)写出a的不同的所有非下降子列:(2)定义某个子列的f值为数列中各个数 ...

  9. golang 常用网址收藏

    1:beego 模板语法指南:http://blog.go-china.org/03-beego-template 2:go 语言sublimetext2配置:http://www.kankanews ...

  10. 51nod1757 大灾变

    能想到二分答案+最大流判断是否符合.但是不知道如何建图qaq.参考的是http://blog.csdn.net/fsss_7/article/details/52132046的建图方法 #includ ...