-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with stored procedure and hibernate
PostPosted: Sat May 21, 2011 6:53 am 
Newbie

Joined: Wed May 18, 2011 4:00 pm
Posts: 2
I got some problem when I am trying to override INSERT, and UPDATE operations in Hibernate. My delete functions works fine, and everything works when i´m not override with my stored procedure, and I have no idea why. When I am trying to make an INSERT, everything seems to be fine but no data is being insert and no excpetion throws.
When I am trying to make an UPDATE following excpetion throws:
Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: could not update: [labb6Hibernate.bil#18]

Here is my hbm.xml file:
Code:
<hibernate-mapping>
  <class catalog="Cars" name="labb6Hibernate.bil" table="Bil">
    <id name="idNum" type="java.lang.Integer">
      <column name="idNum"/>
      <generator class="identity"/>
    </id>
    <property name="marke" type="string">
      <column length="10" name="Marke" not-null="true"/>
    </property>
    <property name="modell" type="string">
      <column length="10" name="Modell" not-null="true"/>
    </property>
    <property name="arsmodell" type="string">
      <column length="4" name="Arsmodell" not-null="true"/>
    </property>
    <sql-insert callable="true"> { call insertCars(?,?,?) }  </sql-insert>
    <sql-update callable="true"> { call updateCars(?,?,?) </sql-update>
    <sql-delete callable="true"> { call deleteCars(?) }  </sql-delete>
  </class>

Here is my UPDATE code:
Code:
Session session = MyHibernateUtil.getSessionFactory().openSession();
       session.beginTransaction();
       int s = Integer.parseInt(idTxt.getText());
       bil Bil = (bil) session.get(bil.class, s);
       Bil.setIdNum(s);
       Bil.setMarke(markeTxt.getText());
       Bil.setModell(modellTxt.getText());
       Bil.setArsmodell(arsmodellTxt.getText());
       session.update(Bil);
       session.getTransaction().commit();
       session.close();

Here is my INSERT code:
Code:
Session session = MyHibernateUtil.getSessionFactory().openSession();
       session.beginTransaction();       
       bil Bil = new bil();
       Bil.setMarke(markeTxt.getText());
       Bil.setModell(modellTxt.getText());
       Bil.setArsmodell(arsmodellTxt.getText());
       session.save(Bil);
       session.getTransaction().commit();
       session.close();

Does anyone have an idea what is wrong in my code?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.