Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate DAO doesn't insert row into database MyEclipse
    text
    copied!<p>I'm trying to insert a new object into my database. I followed a step-by-step tutorial but it seems it doesn't work for me. In the tutorial there was the following line :</p> <p>Transaction tx = dao.GetSession().beginTransaction();</p> <p>The GetSession doesn't pop up, i get the error "GetSession() is not visible from DaoHibernateSupport". I replaced the line with the following :</p> <pre><code>Transaction tx = dao.getSessionFactory().getCurrentSession().beginTransaction(); </code></pre> <p>but then i got a null Exception on the currentSession.</p> <p>I read online and added the <code>current_session_context property</code>, set as "<code>thread</code>". </p> <p>Everything seems to work now, i don 't get any Exception but still no rows are inserted into my MySql database. The table is InnoDB. </p> <p>Here is my final code:</p> <pre><code> Banner banner = new Banner(); banner.setUrl(url); banner.setCategorie(categorie); banner.setCuvinteCheie(cuvinte_cheie); banner.setMaxCpc(cpc); banner.setPath(cale); banner.setPaththumb(caleThumb); banner.setAdvertiserId(Integer.parseInt(session.getAttribute("UserID").toString())); BannerDAO dao = new BannerDAO(); SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); dao.setSessionFactory(sessionFactory); Transaction tx = dao.getSessionFactory().getCurrentSession().beginTransaction(); dao.save(banner); tx.commit(); dao.getSessionFactory().getCurrentSession().close(); </code></pre> <ul> <li><p>So no exceptions raised here, but when i access the database there are no rows in the table.</p> <p>Can you please help me ? Thank you!</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload