-->
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.  [ 6 posts ] 
Author Message
 Post subject: Possible update bug in 2.1 final?
PostPosted: Tue Dec 16, 2003 8:15 pm 
Beginner
Beginner

Joined: Tue Sep 02, 2003 12:15 pm
Posts: 33
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<!-- com.tab.core.shared.vo.TAB_Account root -->
<class name="com.tab.core.shared.vo.TAB_Account" table="tab_account">
<composite-id name="key" class="com.tab.core.shared.vo.TAB_AccountPK">
<key-property name="accountNum" column="acct_num" type="integer"/>
</composite-id>
<property name="balance" column="balance" type="com.tab.core.server.types.IntToDoubleType"/>
<property name="lastUptime" column="last_uptime" type="integer"/>
<property name="lastDelinquent" column="last_delinquent" type="com.tab.core.server.types.IntToCalendarType"/>
<property name="sentToBMA" column="senttobma" type="com.tab.core.server.types.IntToCalendarType"/>
<property name="closed" column="closed" type="com.tab.core.server.types.IntToCalendarType"/>
<property name="chargeoffDate" column="chgoff_date" type="com.tab.core.server.types.IntToCalendarType"/>
<property name="appType" column="app_type" type="string"/>
<property name="accountType" column="acct_type" type="integer"/>
<property name="taxType" column="tax_type" type="character"/>
<property name="interestDay" column="interest_day" type="integer"/>
<property name="sumDeposits" column="sum_deposits" type="com.tab.core.server.types.CharToBooleanType"/>
<property name="serviceChargeDay" column="serv_chg_day" type="integer"/>
<property name="statementDay" column="stmt_day" type="integer"/>
<property name="createCard" column="create_card" type="com.tab.core.server.types.CharToBooleanType"/>
<component name="chargeoffReason" class="com.tab.core.shared.vo.TAB_ChargeoffReasonPK">
<property name="reason" column="chgoff_reason" type="integer"/>
</component>
<property name="dailyATMTransactions" column="daily_atm" type="com.tab.core.server.types.IntToDoubleType"/>
<property name="issueChecks" column="checks" type="com.tab.core.server.types.CharToBooleanType"/>
<property name="lastPaymentAmount" column="last_pmt_amt" type="com.tab.core.server.types.IntToDoubleType"/>
<component name="accountStatus" class="com.tab.core.shared.vo.TAB_AcctStatusPK">
<property name="status" column="status" type="character"/>
</component>
<property name="lastUpdate" column="last_update" type="com.tab.core.server.types.IntToCalendarType"/>
<property name="employerId" column="emplyr_id" type="integer"/>
<property name="ffActionCode" column="ff_action_code" type="character"/>
<property name="ffNumber" column="ff_num" type="integer"/>
<property name="creditLimit" column="credit_limit" type="com.tab.core.server.types.IntToDoubleType"/>
<property name="lastPaymentDate" column="last_pmt_date" type="com.tab.core.server.types.IntToCalendarType"/>
<property name="opened" column="opened" type="com.tab.core.server.types.IntToCalendarType"/>
<property name="lastUpUser" column="last_upuser" type="string"/>
<property name="officerInitials" column="officer_initials" type="string"/>
<component name="collectionCode" class="com.tab.core.shared.vo.TAB_CollectionCodePK">
<property name="id" column="collection" type="integer"/>
</component>
<property name="accountPin" column="account_pin" type="string"/>
</class>
</hibernate-mapping>

---------------------------------------------------------- End HBM -----------------------------



The class follows the mapping and is pretty straight forward.

Anyway, the problem is this. I start a session and begin a transaction. I load the TAB_Account object, and call setBalance(someAmount) and setStatus(someNewStatus). I then commit the transaction and close the session.
When I do this, the object never gets committed to the database. I found that the only time it will actually commit (I assume get marked as dirty) is if I update one of the fields that isn't either user defined or a component. For example, when I called setEmployerId(someId), it updated. I have tried flushing the session after I set the values, but it doesn't help. I am updating several other objects within the same transaction and they all work fine. Is this a bug, or is there something I am missing?

Thanks

Nic


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 8:41 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
The problem may be with your custom types.
Could you paste one of them here? IntToDoubleType for example.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 8:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Certainly sounds like your implementation of UserType.equals() is broken. I very much doubt that this is a bug in Hibernate.


Top
 Profile  
 
 Post subject: Here's the code for my intToDoubleType
PostPosted: Tue Dec 16, 2003 10:35 pm 
Beginner
Beginner

Joined: Tue Sep 02, 2003 12:15 pm
Posts: 33
It could very easily be something I've misunderstood or overlooked. I have written some custom types to handle our legacy data, so I'm not all that familiar with it. I just want to find out whats going on and correct the problem. I love Hibernate and have ported all of our data access over to it as well as recommended it to everybody I talk to. Thanks for the great work and the help to everyone involved. I can't wait to see the new JBoss with your stuff in it.


This is the custom type I use. It uses NumberUtil which I have used everywhere with our previous system, so I know it works.

Thanks in advance

Nic

---------------------------------------- Begin Class -----------------------------------

package com.tab.core.server.types;



import net.sf.hibernate.UserType;

import net.sf.hibernate.HibernateException;



import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.PreparedStatement;

import java.sql.Types;



import com.tab.core.shared.util.NumberUtil;



/**

* Created by IntelliJ IDEA.

* User: nholbrook

* Date: Sep 8, 2003

* Time: 9:11:31 AM

*/

public class IntToDoubleType implements UserType

{



public IntToDoubleType()

{



}



public int[] sqlTypes()

{

return new int[] { Types.INTEGER };

}



public Class returnedClass()

{

return Double.class;

}



public boolean equals(Object o, Object o1) throws HibernateException

{

return (o == o1) || (o != null && o1 != null);

}



public Object nullSafeGet(ResultSet resultSet, String[] strings, Object o) throws HibernateException, SQLException

{

return NumberUtil.intToDouble(new Integer(resultSet.getInt(strings[0])));

}



public void nullSafeSet(PreparedStatement preparedStatement, Object o, int i) throws HibernateException, SQLException

{

if (o == null)

preparedStatement.setInt(i, 0);

else

preparedStatement.setInt(i, NumberUtil.doubleToInteger(((Double)o)).intValue());

}



public Object deepCopy(Object o) throws HibernateException

{

return o;

}



public boolean isMutable()

{

return true;

}

}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 12:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Code:
return (o == o1) || (o != null && o1 != null);


So whenever both objects are non-null, you consider them to be equal??

This certainly would result in the behavior you observe. Do you mean:

Code:
return (o == o1) || (o == null && o1 == null);


Top
 Profile  
 
 Post subject: Actually yes. Sorry
PostPosted: Wed Dec 17, 2003 11:00 am 
Beginner
Beginner

Joined: Tue Sep 02, 2003 12:15 pm
Posts: 33
Some of these I had cut and pasted from other examples and it looks like I didn't get back to changing them all. I better do a quick run through all my types again. Sorry for the bother.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.