-->
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.  [ 5 posts ] 
Author Message
 Post subject: Inserts and Deletes work, but Updates don't
PostPosted: Wed Apr 07, 2004 2:15 pm 
Newbie

Joined: Thu Apr 01, 2004 12:37 pm
Posts: 9
Hello,

I'm using Hibernate 2.12 with J2EE and Oracle 9i. The problem I'm experiencing is that inserts and deletes to my db work, but updates don't.

--The JUnit test file
Code:
public void testDirectionsInsert()
{
    drData.setDirectionsName("Destin");
    drData.setDirections("Go to 77 Seascape Boulevard.");
    drData.setUserId(new Integer(2));
    drDAO.insert(drData);
}

public void testDirectionsUpdate()
{
    DirectionsData tmp = drDAO.findDirectionsByDirectionsId(new Long(4));
    drData.setDirectionsName("Destin -  Majestic Sun");
    drDAO.update(tmp);
}

public void testDirectionsDelete()
{
    DirectionsData tmp = (DirectionsData)  drDAO.findDirectionsByDirectionsId(7);
}


--The body of the update method called above:
Code:
trans = session.beginTransaction();
session.update(o);
session.flush();
trans.commit();


--And finally, the hbm.xml
Code:
<hibernate-mapping package="com.cendant.trg.getaways.model">
<class name="DirectionsData" table="directions">
  <id name="directionsId" column="directions_id">
   <generator class="sequence">
    <param name="sequence">directions_id_sq</param>
   </generator>
  </id>
  <property name="directionsName" column="directions_name"/>
  <property name="directions" column="directions"/>
  <property name="userId" column="user_id"/>
  <property name="dateModified" column="date_modified"/>
</class>
</hibernate-mapping>


Please help! I don't get any errors. It just doesn't work.

Thanks!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 2:57 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you don't need to call session.update(o) if you are modifying a persistant object in the same session...


http://www.hibernate.org/hib_docs/refer ... ng-data-s7


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 3:03 pm 
Newbie

Joined: Thu Apr 01, 2004 12:37 pm
Posts: 9
Mine is a web app so a db obj's retrieval occurs in a separate session from a update or dlt because most of the time, i'm retrieving info to display only. This is why I perform an session.update.

Btw, here's most of the body of the findDirectionsByDirectionsId method looks like:
Code:
session = HibernateDBConnection.currentSession();
selectedObject = session.load(c, pk);
HibernateDBConnection.closeSession();


Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 4:21 pm 
Newbie

Joined: Thu Apr 01, 2004 12:37 pm
Posts: 9
I figured out my problem...I'm retrieving one object, tmp, but then performing the update on a different object, oData.

One additional question: is there a way to see the values that are being updated i.e. not ?s in the sql stmts?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 2:46 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
looking at sql generated can help


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

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.