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
|