sc.setPrice(sg.getPrice()); insert.save(sc);
//加一句 试一下。
insert.flush();
}
//加一句 试一下。
insert.flush();
}
解决方案 »
- 这是我自己写的一个DAO的封装类
- 寻找javaEE项目打包工具
- 关于调试项目的一个问题
- 求助base64加密算法
- 想学习J2EE,请问有什么好的资料或者书籍推荐,谢谢
- tomcat中,web.xml配置filter出错
- 有关hibernate配置文件的疑问?
- 怪事年年有,今天特别多!我配置WIN2000 + JB8 + Weblogic7 可以在JB8里编写和上传Bean给Weblogic7了,但我的JSP部分却编译不过了?
- 刷新重复from重复提交怎么解决?求教!!!
- 现在做项目有用JSF+Primeface这个框架的吗
- 运行hibernate时间的两句话帮忙看看什么意思
- javamail.
把Shoppingcart sc=new Shoppingcart();
放到 while(it.hasNext()){
Shoppingcart sc=new Shoppingcart();
sg=(Subgoods)it.next();
sc.setName(sg.getName());
sc.setPrice(sg.getPrice());
insert.save(sc);
}
Transaction t=insert.beginTransaction();
Query q=select.createQuery("from Subgoods where id="+Integer.valueOf(id[i]));
List l=q.list();
Iterator it=l.iterator();
while(it.hasNext()){
sg=(Subgoods)it.next();
sc.setName(sg.getName());
sc.setPrice(sg.getPrice());
insert.save(sc);
}
t.commit();
} HibernateSessionFactory.closeSession();
}
just do it
//Session select = HibernateSessionFactory.getSession();
Session insert = HibernateSessionFactory.getSession();
//insert.createQuery("from Shoppingcart");
Transaction t=insert.beginTransaction();
//Subgoods sg=new Subgoods(); for(int i=0;i <id.length;i++){
Query q=select.createQuery("from Subgoods where id="+Integer.valueOf(id[i]));
List l=q.list();
Iterator it=l.iterator();
while(it.hasNext()){
Subgoods sg=(Subgoods)it.next();
Shoppingcart sc=new Shoppingcart();
sc.setName(sg.getName());
sc.setPrice(sg.getPrice());
insert.save(sc);
}
}
t.commit();
HibernateSessionFactory.closeSession();
}
public static void main(String[] args) {
ConnectionDB con=new ConnectionDB();
String id[]={"1","4"};
con.selectId(id);
}
memoordit兄弟,你的是对的..
为什么,在while中每循环一次就得创建Subgoods sg=(Subgoods)it.next();
Shoppingcart sc=new Shoppingcart(); 这个呢..