Hi
I am not able to
update a record into mysql. After the update method is executed, the record remains unchanged. I do not have any problem in inserting a new record. I have checked the table and the primary key is properly defined.
Following are the details of the problem:
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.hunza.kcw.bus.User" table="KCWUSERS">
<!-- A 32 hex character is our surrogate key. It's automatically
generated by Hibernate with the UUID pattern. -->
<id name="userId" column="USERID">
<generator class="increment"/>
</id>
<property name="userName">
<column name="USERNAME"/>
</property>
<property name="password">
<column name="PASSWORD"/>
</property>
<property name="email">
<column name="EMAIL"/>
</property>
<property name="lastLogOn">
<column name="LASTLOGON"/>
</property>
<property name="address1">
<column name="ADDRESS1"/>
</property>
<property name="address2">
<column name="ADDRESS2"/>
</property>
<property name="city">
<column name="CITY"/>
</property>
<property name="state">
<column name="STATE"/>
</property>
<property name="zip">
<column name="ZIP"/>
</property>
<property name="phone">
<column name="PHONE"/>
</property>
<property name="shippingAddress1">
<column name="SHIPPINGADDRESS1"/>
</property>
<property name="shippingAddress2">
<column name="SHIPPINGADDRESS2"/>
</property>
<property name="shippingCity">
<column name="SHIPPINGCITY"/>
</property>
<property name="shippingState">
<column name="SIHPPINGSTATE"/>
</property>
<property name="shippingZip">
<column name="SHIPPINGZIP"/>
</property>
<property name="shippingPhone">
<column name="SHIPPINGPHONE"/>
</property>
<property name="nameOnCard">
<column name="NAMEONCARD"/>
</property>
<property name="creditCardNumber">
<column name="CREDITCARDNUMBER"/>
</property>
<property name="expirationDate">
<column name="EXPIRATIONDATE"/>
</property>
<property name="cvv">
<column name="CVV"/>
</property>
<property name="comments">
<column name="COMMENTS"/>
</property>
<property name="sendUpdates">
<column name="SENDUPDATES"/>
</property>
<property name="firstName">
<column name="FIRSTNAME"/>
</property>
<property name="lastName">
<column name="LASTNAME"/>
</property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
I am using the following code to update the record in the database:
Code:
try {
logger.debug("Updating user");
Session session = HibernateUtil.getSession();
Transaction tx = session.beginTransaction();
session.update(user);
tx.commit();
HibernateUtil.closeSession();
logger.debug("User updated successfully");
logger.debug("User ID: " + user.getUserId());
result = true;
} catch (HibernateException ex) {
logger.error("Error while updating the user: " + ex);
}
No Exception is thrown when the above code is executed:
Full stack trace of any exception that occurs:
2006-12-22 17:48:14,587 DEBUG [com.hunza.kcw.db.UserManager] - Updating user
2006-12-22 17:48:14,587 DEBUG [org.hibernate.transaction.JDBCTransaction] - begin
2006-12-22 17:48:14,587 DEBUG [org.hibernate.transaction.JDBCTransaction] - current autocommit status: false
2006-12-22 17:48:14,647 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] - ignoring persistent instance
2006-12-22 17:48:14,647 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] -
object already associated with session: [com.hunza.kcw.bus.User#4]
2006-12-22 17:48:14,647 DEBUG [org.hibernate.transaction.JDBCTransaction] - commit
2006-12-22 17:48:14,647 DEBUG [org.hibernate.transaction.JDBCTransaction] - committed JDBC Connection
2006-12-22 17:48:14,647 DEBUG [com.hunza.kcw.Hibernate.HibernateUtil] - Closing Session of this thread.
2006-12-22 17:48:14,647 DEBUG [org.hibernate.impl.SessionImpl] - closing session
2006-12-22 17:48:14,647 DEBUG [org.hibernate.jdbc.ConnectionManager] - closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2006-12-22 17:48:14,647 DEBUG [org.hibernate.connection.DriverManagerConnectionProvider] - returning connection to pool, pool size: 1
2006-12-22 17:48:14,647 DEBUG [com.hunza.kcw.db.UserManager] - User updated successfully
2006-12-22 17:48:14,647 DEBUG [com.hunza.kcw.db.UserManager] - User ID: 4
Can anyone tell why this is happening? I have been using Hibernate for quite a few months, but this problem has completely stumped me.
Thanks
Rauf