-->
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.  [ 1 post ] 
Author Message
 Post subject: UserType property not being saved
PostPosted: Wed Jun 23, 2004 6:08 pm 
Beginner
Beginner

Joined: Mon May 24, 2004 7:39 pm
Posts: 37
Location: Charlotte
Hello,

I am new to UserTypes because I am migrating from PersistentEnum's (in Hibernate version 2.1.4 with MySQL 4.0.17). I have created a UserType which is shown below. The problem is that if I modify ONLY the UserType property and call saveOrUpdate, the new value will not get saved (but no exception is thrown). But, if I modify the UserType property AND another property as well and call saveOrUpdate, both fields will be saved. Can anyone explain what is going on? Thank you very much for your help.

Joe Hudson

------------------------------------------
// UserType
public class MessageStatusUserType implements UserType {
public Object deepCopy(Object value) throws HibernateException {
if (null == value) return null;
else return MessageStatus.getInstance(((MessageStatus) value).toString());
}
public boolean equals(Object x, Object y) throws HibernateException {
if (null == x || null == y) return false;
else if (x instanceof MessageStatus && y instanceof MessageStatus) {
return x.equals(y);
}
else return false;
}
public boolean isMutable() {
return true;
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws HibernateException, SQLException {
return MessageStatus.getInstance(rs.getString(names[0]));
}
public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {
if (null == value) st.setNull(index, Types.VARCHAR);
else st.setString(index, ((MessageStatus) value).toString());

}
public Class returnedClass() {
return MessageStatus.class;
}
public int[] sqlTypes() {
return new int[] {Types.VARCHAR};
}
}


// Object
public class MessageStatus implements Serializable {

public static final MessageStatus NEW = new MessageStatus("N");
public static final MessageStatus READ = new MessageStatus("R");

private String value;

protected MessageStatus(String value) {
this.value = value;
}

public static MessageStatus getInstance (String value) {
if (value.equals("N")) return NEW;
else if (value.equals("R")) return READ;
else return null;
}

public String getDisplayValue () {
if (value.equals("N")) return "New";
else if (value.equals("R")) return "Read";
else return "Unknown";
}

public String toString() {
return value;
}

public boolean equals (Object obj) {
if (null == obj || (!(obj instanceof MessageStatus))) return false;
else return ((MessageStatus) obj).toString().equals(obj.toString());
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.