steve wrote:
post your Layer3OptionsUserType code
Here it is:
Code:
/**
* A Hibernate Composite User type to handle Layer3Options simple beans
* <p/>
* $Id: Layer3OptionsUserType.java,v 1.3 2005/05/11 02:26:45 bonny Exp $
*/
public class Layer3OptionsUserType implements CompositeUserType
{
public Class returnedClass() { return Layer3Options.class; }
public boolean equals(Object x, Object y)
{
if (x == y) return true;
if (x == null || y == null) return false;
return x.equals(y);
}
public int hashCode(Object o) throws PersistenceException { return o.hashCode(); }
public Serializable disassemble(Object o, SessionImplementor s) throws PersistenceException
{
return (Serializable) deepCopy(o);
}
public Object assemble(Serializable cached, SessionImplementor s, Object owner) throws PersistenceException
{
if (cached == null) return null;
Serializable[] cachedOptions = (Serializable[]) cached;
Layer3Options options = new Layer3Options();
options.setVlanID(((Integer) cachedOptions[0]));
options.setMtu(((Integer) cachedOptions[1]));
options.setRate(((Integer) cachedOptions[2]));
return options;
}
public Object replace(Object original, Object target, SessionImplementor session, Object owner)
throws PersistenceException
{
return assemble(disassemble(original, session), session, owner);
}
public Object deepCopy(Object value)
{
Integer[] source = (Integer[]) value;
Integer[] result = new Integer[source.length];
for (int i = 0; i < result.length; i++)
result[i] = source[i];
return value;
}
public boolean isMutable()
{
return false;
}
public Object nullSafeGet(ResultSet resultSet, String[] names, SessionImplementor session, Object owner)
throws PersistenceException, SQLException
{
if (resultSet.wasNull()) return null;
Layer3Options l3o = new Layer3Options();
l3o.setVlanID(resultSet.getInt(names[0]));
l3o.setMtu(resultSet.getInt(names[1]));
l3o.setRate(resultSet.getInt(names[2]));
return l3o;
}
public void nullSafeSet(PreparedStatement statement, Object value, int index, SessionImplementor session)
throws PersistenceException, SQLException
{
if (value == null)
{
statement.setNull(index + 0, Types.NUMERIC);
statement.setNull(index + 1, Types.NUMERIC);
statement.setNull(index + 2, Types.NUMERIC);
}
else
{
Layer3Options options = (Layer3Options) value;
statement.setInt(index + 0, options.getVlanID());
statement.setInt(index + 1, options.getMtu());
statement.setInt(index + 2, options.getRate());
}
}
public String[] getPropertyNames()
{
return new String[] { "l3vlanid", "l3mtu", "l3rate" };
}
public Type[] getPropertyTypes()
{
return new Type[]
{
Hibernate.INTEGER,
Hibernate.INTEGER,
Hibernate.INTEGER
};
}
public Object getPropertyValue(Object component, int property) throws PersistenceException
{
Layer3Options options = (Layer3Options) component;
switch( property )
{
case 0: return options.getVlanID();
case 1: return options.getMtu();
case 2: return options.getRate();
}
throw new PersistenceException("Unexepected property index when reading Layer3Options properties");
}
public void setPropertyValue(Object component, int property, Object value) throws PersistenceException
{
Layer3Options options = (Layer3Options) component;
switch (property)
{
case 0: options.setVlanID(((Integer) value).intValue()); break;
case 1: options.setMtu(((Integer) value).intValue()); break;
case 2: options.setRate(((Integer) value).intValue()); break;
}
throw new PersistenceException("Unexepected property index when setting Layer3Options properties");
}
}