I use hibernate + sqlite. A lot of time is spent on writing (reading, etc.). On insert 100 lines leaves 1.8s. Maybe I'm doing something wrong or is it a normal delay for hibernate?
public void insert(List<Buffer> buffers) throws SQLException { Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); for (Buffer item : buffers) { session.save(item); } session.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); } finally { if (session != null && session.isOpen()) { session.close(); } } } <hibernate-configuration> <session-factory> <property name="show_sql">true</property> <property name="format_sql">true</property> <property name="dialect">dialect.SQLiteDialect</property> <property name="connection.driver_class">org.sqlite.JDBC</property> <property name="connection.url">jdbc:sqlite:test.db</property> <property name="connection.username"></property> <property name="connection.password"></property> <property name="hibernate.hbm2ddl.auto">update</property> <property name="connection.pool_size">5</property> <property name="current_session_context_class">thread</property> <property name="maxActive">50</property> <mapping resource="User.hbm.xml" /> <mapping resource="Buffer.hbm.xml" /> </session-factory> </hibernate-configuration> <hibernate-mapping> <class name="model.Buffer" table="buffers"> <id name="id" column="id" type="int"> <generator class="native"></generator> </id> <property name="addrA" column="addrA" type="int"></property> <property name="addrB" column="addrB" type="int"></property> <property name="addrC" column="addrC" type="int"></property> <property name="name" column="name" type="string"></property> <property name="valName" column="valName" type="string"></property> <property name="measurements" column="measurements" type="string"></property> <property name="statusPriority" column="statusPriority" type="int"></property> <property name="value" column="value" type="string"></property> <property name="mistake" column="mistake" type="string"></property> <property name="dateEvent" column="dateEvent" type="calendar" not-null="false" length="7"></property> <property name="idEvent" column="idEvent" type="long"></property> </class> </hibernate-mapping> public static void main(String[] args) { try { List<Buffer> buffers = getBuffers(100); long time = System.currentTimeMillis(); BufferHibernate.getInstance().getBusDAO().insert(buffers); System.out.println("insert : " + (System.currentTimeMillis() - time)); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } I tried to run the example http://hibernate-sqlite.googlecode.com/files/HibernateSQLitewithjar.rar the result is the same, only now one record took 1.6s.
The biggest delay when opening a session is Session session = HibernateUtil.getSessionFactory (). OpenSession ();
It is necessary to write to the database every second in different streams. I thought before each recording to open the session, record and bury. It turns out the opening is heavy and should be open for the duration of the program? There will be no conflicts?