List of usage examples for org.hibernate Session clear
void clear();
From source file:cloudoutput.database.HibernateUtil.java
License:Open Source License
/** * Closes a given database session./*from w ww . j av a2 s. c o m*/ * * @param session the session to be closed. * @since 1.0 */ public static void closeSession(Session session) { if (session != null) { session.clear(); session.close(); } }
From source file:cn.lhfei.airqa.dao.support.Hibernate4DaoSupport.java
License:Apache License
public void batchInsert(List<E> list) { Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); for (int i = 0; i < list.size(); i++) { session.save(list.get(i));//from www . j a v a2 s . com if (i % 50 == 0) { //50, same as the JDBC batch size //flush a batch of inserts and release memory: session.flush(); session.clear(); } } tx.commit(); session.close(); }
From source file:cn.newtouch.model.TeacherTest.java
License:Open Source License
@Test public void testClear() { Session session = HibernateUtil.getSession(); session.beginTransaction();//w ww. j av a 2 s . c o m Teacher t = (Teacher) session.load(Teacher.class, 1); System.out.println(t.getName()); session.clear(); Teacher t2 = (Teacher) session.load(Teacher.class, 1); System.out.println(t2.getName()); session.getTransaction().commit(); }
From source file:cn.newtouch.model.TeacherTest.java
License:Open Source License
@Test public void testFlush() { Session session = HibernateUtil.getSession(); session.beginTransaction();/* w ww .ja va 2 s . c o m*/ Teacher t = (Teacher) session.load(Teacher.class, 1); t.setName("tttt"); session.clear(); t.setName("ttttt"); session.getTransaction().commit(); }
From source file:cn.sharek.bsg.machine.dao.impl.DMLDaoImpl.java
@Override public void save(Collection<T> entities, Session session) throws Exception { int i = 0;//from w ww . j a va 2 s .co m //??? for (Object obj : entities) { session.save(obj); i++; //?? if (0 == i % 10) { session.flush();//? session.clear();// } } }
From source file:cn.sharek.bsg.machine.dao.impl.DMLDaoImpl.java
@Override public void delete(Collection<T> entities, Session session) throws Exception { int i = 0;/*from w w w . j a v a 2s . c om*/ //??? for (Object obj : entities) { session.delete(obj); i++; //?? if (0 == i % 10) { session.flush();//? session.clear();// } } }
From source file:com.advdb.footballclub.FootBallClub.java
private void createCompetition(Session session, int length) { Transaction transaction = null;/* w ww . ja v a 2 s . c om*/ try { System.out.println("start createCompetition."); transaction = session.beginTransaction(); Calendar date = new GregorianCalendar(); int endYear = date.get(Calendar.YEAR); for (int year = endYear - length; year <= endYear; year++) { for (String competitionName : COMPETITION_NAME_ARR) { int seasonStartYear = year; int seasonEndYear = seasonStartYear + 1; String seasonName = seasonStartYear + "/" + seasonEndYear; DimCompetition d = new DimCompetition(competitionName, seasonName, seasonStartYear, seasonEndYear); session.save(d); } session.flush(); session.clear(); } transaction.commit(); System.out.println("finish createCompetition."); } catch (HibernateException e) { if (transaction != null) { transaction.rollback(); } } }
From source file:com.advdb.footballclub.FootBallClub.java
private void createTactic(Session session) { Transaction transaction = null;/* w w w .j av a 2 s .c om*/ try { System.out.println("start createTactic."); transaction = session.beginTransaction(); for (int i = 0; i < TACTIC_INSTRUCTION_ARR.length; i++) { DimTactic d = new DimTactic(TACTIC_NAME_ARR[i], TACTIC_INSTRUCTION_ARR[i]); session.save(d); } session.flush(); session.clear(); transaction.commit(); System.out.println("finish createTactic."); } catch (HibernateException e) { if (transaction != null) { transaction.rollback(); } } }
From source file:com.advdb.footballclub.FootBallClub.java
private void createOpponent(Session session) { Transaction transaction = null;/* w ww . j a v a2 s. com*/ try { System.out.println("start createOpponent."); transaction = session.beginTransaction(); Reader in = new FileReader("/Users/apichart/Documents/DW_opponent/DimOpponent-Table 1.csv"); Iterable<CSVRecord> records = CSVFormat.DEFAULT.parse(in); for (CSVRecord record : records) { String longName = record.get(2); String shortName = record.get(3); DimOpponent d = new DimOpponent(longName, shortName); session.save(d); } in.close(); session.flush(); session.clear(); transaction.commit(); System.out.println("finish createOpponent."); } catch (HibernateException e) { if (transaction != null) { transaction.rollback(); } } catch (FileNotFoundException ex) { Logger.getLogger(FootBallClub.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(FootBallClub.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.advdb.footballclub.FootBallClub.java
private void createPlayer(Session session) { Transaction transaction = null;/* www. ja v a 2 s.c o m*/ try { System.out.println("start createPlayer."); transaction = session.beginTransaction(); Reader in = new FileReader("/Users/apichart/Documents/DW_opponent/DimPlayer-Table 1.csv"); Iterable<CSVRecord> records = CSVFormat.DEFAULT.parse(in); for (CSVRecord record : records) { String name = record.get(2); String nationality = record.get(3); String value = record.get(4); String height = record.get(6); String weight = record.get(7); DimPlayer d = new DimPlayer(name, nationality, Double.valueOf(value), Double.valueOf(height), Double.valueOf(weight)); session.save(d); } in.close(); session.flush(); session.clear(); transaction.commit(); System.out.println("finish createPlayer."); } catch (HibernateException e) { if (transaction != null) { transaction.rollback(); } } catch (FileNotFoundException ex) { Logger.getLogger(FootBallClub.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(FootBallClub.class.getName()).log(Level.SEVERE, null, ex); } }