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

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. iOS:核心动画之转场动画CATransition

    转场动画——CATransition CATransition是CAAnimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果.iOS比Mac OS X的转场动画效果少一点 U ...

  2. SRM 620 DIV1 L2

    题意:有n个等长的string(设string的长度为m),string中的字符从'A'到'Z',容许对m列执行稳定的排序操作,问说是否能通过这m种操作将这n个string调整成对应的顺序. 题解: ...

  3. Model元数据解析

    Model 元数据是针对数据类型的一种描述信息,主要用于控制数据类型本身及其成员属性在界面上的呈现方式,同时也为Model 绑定和验证提供必不可少的元数据信息.一个复杂数据类型通过属性的方式定义了一系 ...

  4. SPOJ 370 Ones and zeros BFS + 同余剪枝

    题意:给一些n,求出最小的只包含0,1的n的倍数 设两数a, b满足: a < b 并且a % n = b % n. 如果 ( a * 10^x + c ) % n = z , 根据同余定理,( ...

  5. 【USACO】Transformations

    A square pattern of size N x N (1 <= N <= 10) black and white square tiles is transformed into ...

  6. Android 判断用户2G/3G/4G移动数据网络

    Android 判断用户2G/3G/4G移动数据网络 在做 Android App 的时候,为了给用户省流量,为了不激起用户的愤怒,为了更好的用户体验,是需要根据用户当前网络情况来做一些调整的,也可以 ...

  7. Cadence ORCAD CAPTURE元件库介绍

    Cadence ORCAD CAPTURE元件库介绍 来源:Cadence 作者:ORCAD 发布时间:2007-07-08 发表评论 Cadence  OrCAD  Capture 具有快捷.通用的 ...

  8. hiho #1332 : 简单计算器 栈+递归

    #1332 : 简单计算器 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 编写一个程序可以完成基本的带括号的四则运算.其中除法(/)是整除,并且在负数除法时向0取整.( ...

  9. Android实现自定义字体

    介绍 最近在看开源项目的时候,发现里面涉及到了自定义字体,虽然自己目前还用不到,但是动手demo笔记记录一下还是有必要的,没准哪天需要到这个功能. 原理 1.其实实现起来非常简单,主要是用到了Type ...

  10. gulp some tips

    gulp作为替代grunt的task runner后起之秀,基于nodejs的stream操作模型,大大减少了对磁盘的操作因此大大提高了性能. gulp error handling var gulp ...