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.  [ 11 posts ] 
Author Message
 Post subject: "Row was updated ... by another trx" due to custom type ?
PostPosted: Mon May 02, 2011 1:03 pm 
Newbie

Joined: Mon May 02, 2011 10:46 am
Posts: 9
Hi,
(Hibernate 3.3.1 on Oracle 10g)

1/ I have a table CONTACT_INFO with column
ADDITIONAL_EMAIL that will contain email
addresses separated by semi-colons;

2/ the pojo to which this table will be mapped
has the following set- getters:
{code}
public class ContactInfo {...
public java.lang.String[] getAdditionalEMail()
{
int size = _additionalEMailList.size();
java.lang.String[] mArray = new java.lang.String[size];
for (int index = 0; index < size; index++) {
mArray[index] = (String)_additionalEMailList.get(index);
}
return mArray;
}
...
public void setAdditionalEMail(java.lang.String[] additionalEMailArray)
{
//-- copy array
_additionalEMailList.clear();
for (int i = 0; i < additionalEMailArray.length; i++) {
_additionalEMailList.add(additionalEMailArray[i]);
}
}
{code}
it results from a Castor-generated XSD (and I can't do
nothing about it);

3/ it's mapped through the following line:
{code}
<property name="additionalEMail" type="my.pkg.usertypes.CustomStringToStringArrayType" column="ADDITIONAL_EMAIL" length="400" />
{code}

and the PK of this table is defined in the mapping
as follows:
{code}
<id name="id" type="int">
<column name="ID" precision="10" scale="0" />
<generator class="assigned" />
</id>
{code}
(the value comes from a sequence managed through a trigger)

4/ in the custom-type class the nullSafeGet/Set's are:
{code}
public Object nullSafeGet(ResultSet inResultSet, String[] names, Object o)
throws HibernateException, SQLException {

String val = (String)Hibernate.STRING.nullSafeGet(inResultSet, names[0]);
if (val == null) {
String empty[] = new String[0];
return empty;
} else {
String result = val.replaceAll(" ", "");
return result.split(";");
}
}

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

String val[] = (String[])o;

if (val != null && val.length>0)
{
StringBuffer result = new StringBuffer();
int len = val.length;
for (int j=0; j<len; j++)
if (j == len-1)
result.append(val[j]);
else
result.append(val[j]+";");
inPreparedStatement.setString(i, result.toString());

}else{
inPreparedStatement.setString(i, "");
}
}
{code}

5/ I *can't* change this String array in the pojo, I have
no choice;

6/ an update works perfectly, the problem is when I try to
insert a new row in my table, I get this "Row was updated
or deleted by another transaction (or unsaved-value mapping
was incorrect)", I've noticed that Hibernate does an insert,
then right away tries to update (the error msg gives this:
ContactInfo#0);

7/ if I remove the line of mapping
{code}
<property name="additionalEMail"
type="my.pkg.usertypes.CustomStringToStringArrayType" ...
{code}

all works fine (but I can't handle additionalEmail any
longer of course);

8/ I have to add that the error occurs *all the time*,
whether ContactInfo.additionalEmail string array is
null/empty or not..., it looks as if this line of mapping
above has Hibernate trigger an update even if there's no
additional email data: is the code above in my custom type
in ยง4 the reason why Hibernate tries to perform this update ?

Anybody could enlighten me please, and perhaps give me
a solution ??

In advance, thanks very much.
Regards,
Seb


Top
 Profile  
 
 Post subject: Re: "Row was updated ... by another trx" due to custom type ?
PostPosted: Tue May 03, 2011 12:13 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
do not keep session object in two different collection in the same transaction scope.that might solve not sure.

_additionalEMailList

java.lang.String[] mArray

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject: Re: "Row was updated ... by another trx" due to custom type ?
PostPosted: Wed May 04, 2011 3:13 am 
Newbie

Joined: Mon May 02, 2011 10:46 am
Posts: 9
> do not keep session object in two different collection in the same transaction scope
Yes but unfortunately as I said I can't modify my pojo (it is part of a protocol entirely
made through Castor, I can't modify the XSD that yields these classes, I'm not allowed
to do that)...
Forgot to say that I do the following in my DAO:
~ ContactInfo contactInfo = new ContactInfo();
~ contactInfo.setParentId(parentId.intValue());
~ contactInfo.setLastUpdateDate(new Date());
~ session.save(contactInfo);
~ contact.addContactInfo(contactInfo);
~ ...
then
~ session.flush(); <= which causes the exception

I tried to add
~ session.save(contact);
or
~ session.saveOrUpdate(contactInfo);
just after "session.save(contactInfo);" and to play with different
values of the unsaved-value attribute of contactInfo.ID, but to
no avail...

Thanks.
Seb


Top
 Profile  
 
 Post subject: Re: "Row was updated ... by another trx" due to custom type ?
PostPosted: Wed May 04, 2011 3:22 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
post your hbm files.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject: Re: "Row was updated ... by another trx" due to custom type ?
PostPosted: Wed May 04, 2011 7:12 am 
Newbie

Joined: Mon May 02, 2011 10:46 am
Posts: 9
Here it is:

<?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="my.pkg.protocol.ContactInfo" table="BENE_CUST_CONTACT_INFO" dynamic-update="true" dynamic-insert="true">
<id name="id" type="int">
<column name="ID" precision="10" scale="0" />
<generator class="assigned" />
</id>
<version name="lastUpdateVersion" column="LAST_UPDATE_VERSION"/>

<property name="parentId" type="int" update="false">
<column name="PARENT_ID" precision="10" scale="0" />
</property>
<component name="contactInfoInfo">
<property name="privateFixedTelephoneNbr" type="string" column="PRIVATE_FIXED_TELEPHONE" length="20" />
<property name="faxNbr" type="string" column="FAX" length="20" />
<property name="EMail" type="string" column="EMAIL" length="60" />
<property name="additionalEMail" type="string" column="ADDITIONAL_EMAIL" length="400" />
</component>
<property name="creationTimestamp" type="timestamp">
<column name="CREATION_DATE" length="7" not-null="true" />
</property>
<property name="creationUser" type="string">
<column name="CREATION_USER" length="20" not-null="true" />
</property>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: "Row was updated ... by another trx" due to custom type ?
PostPosted: Wed May 04, 2011 11:40 pm 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
define unsaved-value for id .might be 0 for int column type.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject: Re: "Row was updated ... by another trx" due to custom type ?
PostPosted: Thu May 05, 2011 3:08 am 
Newbie

Joined: Mon May 02, 2011 10:46 am
Posts: 9
Already tried that, I get the same error msg.


Top
 Profile  
 
 Post subject: Re: "Row was updated ... by another trx" due to custom type ?
PostPosted: Thu May 05, 2011 12:38 pm 
Regular
Regular

Joined: Mon Apr 19, 2004 6:54 pm
Posts: 79
Check your custom user type, in particular isMutable().

Have a look to this article:
http://blog.xebia.com/2009/11/understanding-and-writing-hibernate-user-types/.

Christophe


Top
 Profile  
 
 Post subject: Re: "Row was updated ... by another trx" due to custom type ?
PostPosted: Fri May 06, 2011 5:38 am 
Newbie

Joined: Mon May 02, 2011 10:46 am
Posts: 9
Modified the isMutable() to return true: failed; also modified
the deepCopy (to return an array copy of object if it is not null),
failed too.


Top
 Profile  
 
 Post subject: Re: "Row was updated ... by another trx" due to custom type ?
PostPosted: Mon May 09, 2011 6:19 am 
Newbie

Joined: Mon May 02, 2011 10:46 am
Posts: 9
I'm giving up the track I started following above: I intend
to get rid of my customer type and try to see if I couldn't
deal with this using the <array> mapping element.
Posted another message:
Mapping String array to VARCHAR with <array>.


Top
 Profile  
 
 Post subject: Re: "Row was updated ... by another trx" due to custom type ?
PostPosted: Mon May 09, 2011 11:09 am 
Newbie

Joined: Mon May 02, 2011 10:46 am
Posts: 9
Didn't give up eventually, and even found a solution. I overrided
~ public boolean equals(Object, Object)
in my customer type, because if new String("xxx").equals(new String("xxx")) indeed,
on the other hand when you have
~ String[] stra1 = new String[]{"xxx"};
~ String[] stra2 = new String[]{"xxx"};

=> stra1.equals(stra2) is false, yet in my case I want it to be true, that's what
I dealt with in my own 'equals()' implementation.

Regards,
Seb


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