Hi All,
I have extended the ClobStringType to provide custom handling to a clob text. I am stuck with a strange problem.
This field is one of the instance variable of the managed entity. Whenever there is a change in this field only and there is no change in other instance variables (i.e. other columns) then Hibernate is not updating the managed entity.
When there is change in other columns as well, Hibernate updates the managed entity. Other fields are simple strings.
Please let me know what can I do and what possibly is going wrong here.
Here is the handler code:
Code:
public class VCardClobType extends ClobStringType {
public VCardClobType() {
super();
}
protected VCardClobType(LobHandler lobHandler,
TransactionManager jtaTransactionManager) {
super(lobHandler, jtaTransactionManager);
}
protected Object nullSafeGetInternal(ResultSet resultSet, String[] columns,
Object owner, LobHandler lobHandler) throws SQLException,
HibernateException {
if (columns == null || columns.length != 1)
throw new HibernateException(
"Only one column name can be used for the " + getClass()
+ " user type");
InputStream reader = lobHandler.getClobAsAsciiStream(resultSet,
columns[0]);
if (reader == null)
return null;
Contact contact = null;
try {
/
contact = VCardUtil.parseContact(reader);
} catch (Exception e) {
throw new HibernateException("cannot read Vcard stream", e
.getCause());
} finally {
if (reader != null)
try {
reader.close();
} catch (Exception e) {
}
}
return contact;
}
protected void nullSafeSetInternal(PreparedStatement statement, int index,
Object value, LobCreator lobCreator) throws SQLException,
HibernateException {
String vCardStr = null;
if (value != null)
try {
vCardStr = VCardUtil.getVCardString((Contact) value);
} catch (Exception e) {
throw new HibernateException("cannot write Vcard stream", e
.getCause());
}
super.nullSafeSetInternal(statement, index, vCardStr, lobCreator);
}
public Object deepCopy(Object value) throws HibernateException {
if (value == null)
return null;
try {
return VCardUtil.copy(((Contact) value));
} catch (IllegalAccessException e) {
log.error("error while copying vcard: "
+ ((Contact) value).toString());
// e.printStackTrace();
} catch (InvocationTargetException e) {
log.error("error while copying vcard: "
+ ((Contact) value).toString());
// e.printStackTrace();
}
return null;
}
public Class returnedClass() {
return Contact.class;
}
public boolean isMutable() {
return true;
}
}
Any help would be highly appreciated.