public void insertWorkProjects(List<WorkProjectVO> listWorkProject)
throws CustomException {
Session session = null;
Transaction transaction = null;
try {
session = HibernateSessionFactory.getSession();
transaction = session.beginTransaction();
//循环保存工作计划的每条任务
for(int i=0;i<listWorkProject.size();i++){
WorkProjectVO workProjectVO = listWorkProject.get(i);
WorkProject workProject = new WorkProject();
BeanUtils.copyProperties(workProject, workProjectVO);
//空格
workProject.setRemark(Hibernate.createClob(" "));
session.save(workProject);
// 调用flush方法,强制Hibernate立即执行insert sql
session.flush();
// 通过refresh方法,强制Hibernate执行select for update
session.refresh(workProject, LockMode.UPGRADE);
// 向Clob写入实际内容#
SerializableClob cb = (SerializableClob)workProject.getRemark();
java.sql.Clob wrapClob = cb.getWrappedClob();
if(wrapClob instanceof oracle.sql.CLOB){
oracle.sql.CLOB clob=(oracle.sql.CLOB) wrapClob;
java.io.Writer writer = clob.getCharacterOutputStream();
writer.write(workProjectVO.getRemarkStr());
writer.close();
}
session.save(workProject);
}
transaction.commit();
} catch (HibernateException e) {
sysLogger.error(e.getMessage());
if (null != transaction) {
transaction.rollback();
}
throw new CustomException(e, msgBaseHibernateDAO001);
} catch (CustomException e) {
sysLogger.error(e.getMessage());
if (null != transaction) {
transaction.rollback();
}
throw e;
} catch (Exception e) {
sysLogger.error(e.getMessage());
if (null != transaction) {
transaction.rollback();
}
throw new CustomException(e, msgBaseHibernateDAO001);
} finally {
if (null != session) {
HibernateSessionFactory.closeSession();
}
}
}
throws CustomException {
Session session = null;
Transaction transaction = null;
try {
session = HibernateSessionFactory.getSession();
transaction = session.beginTransaction();
//循环保存工作计划的每条任务
for(int i=0;i<listWorkProject.size();i++){
WorkProjectVO workProjectVO = listWorkProject.get(i);
WorkProject workProject = new WorkProject();
BeanUtils.copyProperties(workProject, workProjectVO);
//空格
workProject.setRemark(Hibernate.createClob(" "));
session.save(workProject);
// 调用flush方法,强制Hibernate立即执行insert sql
session.flush();
// 通过refresh方法,强制Hibernate执行select for update
session.refresh(workProject, LockMode.UPGRADE);
// 向Clob写入实际内容#
SerializableClob cb = (SerializableClob)workProject.getRemark();
java.sql.Clob wrapClob = cb.getWrappedClob();
if(wrapClob instanceof oracle.sql.CLOB){
oracle.sql.CLOB clob=(oracle.sql.CLOB) wrapClob;
java.io.Writer writer = clob.getCharacterOutputStream();
writer.write(workProjectVO.getRemarkStr());
writer.close();
}
session.save(workProject);
}
transaction.commit();
} catch (HibernateException e) {
sysLogger.error(e.getMessage());
if (null != transaction) {
transaction.rollback();
}
throw new CustomException(e, msgBaseHibernateDAO001);
} catch (CustomException e) {
sysLogger.error(e.getMessage());
if (null != transaction) {
transaction.rollback();
}
throw e;
} catch (Exception e) {
sysLogger.error(e.getMessage());
if (null != transaction) {
transaction.rollback();
}
throw new CustomException(e, msgBaseHibernateDAO001);
} finally {
if (null != session) {
HibernateSessionFactory.closeSession();
}
}
}