Hello all.
I am just wondering if it is normal for a script to insert 50 rows in my database to take several minutes using Hibernate.
My database has 12 tables.
The thing I am wondering if it is correct to do is create a new Session each time I make an insert. I will not paste all my code, but here is how I insert into the database with each table.
Code:
kategori.setId("" + System.currentTimeMillis());
kategori.setKnavn(csv.get("kategori"));
session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.save(kategori);
session.getTransaction().commit();
This code I repeat for every table I have. What I am wondering is, is it correct to get the session, begin, save and commit each time?
I would guess it would suffice to create the session once, and commit at the end when the script is finished, and when I insert into tables, I just do something like this:
session.beginTransaction();
ssession.save();
But I get an exception saying session is not open when I try to beginTransaction.
Hope to get some answer so maybe my loading time will be reduced greatly.
Thanks