I am new to hibernate and I am trying to to make inserts with storere procedures on my MySQL database. I have no problem to get information from it, the problem become when I am trying to insert data to it.
Here is my code in the hbm.xml file (It is only the part where I am trying to implement my store procedure that are going to insert values in database):
Code:
<sql-query name="insertCarsSP" callable="true">
<return alias="cars" class="labb6Hibernate.bil">
</return>
{ call insertCars(?,?,?) }
</sql-query>
Here is a part of the Java code:
Code:
Session session = MyHibernateUtil.getSessionFactory().openSession();
org.hibernate.Query q = session.getNamedQuery("insertCarsSP");
q.setParameter(0, "Saab");
q.setParameter(1, "9000");
q.setParameter(2, "1999");
session.getTransaction().commit();
session.close();
The store procedure is working fine.
I got following error message when I am trying to execute:
"Exception in thread "AWT-EventQueue-0" org.hibernate.TransactionException: Transaction not successfully started"
Does anyone have any suggestion?