Como resolver "could not deserialize"
21/03/2017 17:07
Classjava.io.InvalidClassExceptionMessageError processing GroovyPageView: Error executing tag <g:render>: Error executing tag <g:render>: could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserializeCaused byejTypes.Avatar; local class incompatible: stream classdesc serialVersionUID = 4549713512343945284, local class serialVersionUID = 1
package ejTypes
import javax.smartcardio.Card
/**
* Created by PedroGentil on 18/11/2016.
*/
class Cardinalidade implements Serializable {
private static final long serialVersionUID = 1L;
private Byte valor = null
static ArrayList list = ['(1,1)','(1,N)','(N,1)','(N,N)']
static ArrayList getList () {
return list
}
static toByte (String sArg) {
Byte result
switch (sArg) {
case ['(1,1)','1:1']:
result = 1
break
case ['(1,N)','1:N']:
result = 2
break
case ['(N,1)','(N:1)']:
result = 3
break
case ['(N,N)','(N:N)']:
result = 4
break
default:
result = 1
break
}
return result
}
public Cardinalidade(String sArg) {
this.valor = this.toByte (sArg)
}
public Cardinalidade(Object o) {
if (o == null) {
this.valor = null
} else if (o instanceof Byte) {
if ((o<=7) && (o>0)) {
this.valor = o
} else {
this.valor = null
}
this.valor = o
} else if (o instanceof String) {
this.valor = this.toByte(sArg)
} else if (o instanceof Cardinalidade) {
this.valor = o.valor
} else {
this.valor = null
}
}
public Cardinalidade(Cardinalidade value) {
this.valor = value.valor
}
public Cardinalidade(Byte value) {
this.valor = value
}
static mapping = {
valor sqlType: 'BYTE'
}
public String toString() {
String result
switch (this.valor) {
case 1:
result = 'Domingo'
break
case 2:
result = 'Segunda-feira'
break
case 3:
result = 'Terça-feira'
break
case 4:
result = 'Quarta-feira'
break
case 5:
result = 'Quinta-feira'
break
case 6:
result = 'Sexta-feira'
break
case 7:
result = 'Sábado'
break
default:
result = ' - '
break
}
return result
}
public String to3Digitos () {
String result
switch (this.valor) {
case 1:
result = 'Dom'
break
case 2:
result = 'Seg'
break
case 3:
result = 'Ter'
break
case 4:
result = 'Qua'
break
case 5:
result = 'Qui'
break
case 6:
result = 'Sex'
break
case 7:
result = 'Sab'
break
default:
result = ' - '
break
}
return result
}
private static class SerializationProxy
implements Serializable {
private Byte valor = null
public SerializationProxy() { }
public SerializationProxy(Cardinalidade object) {
valor = object.valor;
}
Object readResolve() {
return new Cardinalidade(valor) {};
}
}
private Object writeReplace() {
return new SerializationProxy(this);
}
}
package ejTypes
import org.hibernate.HibernateException
import org.hibernate.engine.spi.SessionImplementor
import java.sql.PreparedStatement
import java.sql.ResultSet
import java.sql.SQLException
import java.sql.Types
/**
* Created by PedroGentil on 13/09/2016.
*/
class CardinalidadeType implements org.hibernate.usertype.UserType {
private static final SQL_TYPES = [Types.TINYINT] as int[]
/**
* Returns the object from the 2 level cache
*/
@Override
public Object assemble(Serializable cached, Object owner) throws HibernateException {
//would work as the AuditData.class is Serializable,
//and stored in cache as it is - see disassemble
return cached
}
/**
* Used to create Snapshots of the object
*/
@Override
public Object deepCopy(Object o) throws HibernateException {
//return value; -> if AuditData.class was immutable we could return the object as it is
final Cardinalidade cardinalidade
if (o == null) {
return null
} else {
if (o instanceof Cardinalidade) {
cardinalidade = new Cardinalidade(o?.valor);
} else {
//final Cardinalidade recievedParam = (Cardinalidade) o;
cardinalidade = new Cardinalidade(o);
}
}
return cardinalidade;
}
/**
* method called when Hibernate puts the data in a second level cache. The data is stored
* in a serializable form
*/
@Override
public Serializable disassemble(final Object value) throws HibernateException {
//For this purpose the AuditData.class must implement serializable
return (Serializable) value;
}
/**
* Used while dirty checking - control passed on to the {@link Avatar}
*/
@Override
public boolean equals(final Object o1, final Object o2) throws HibernateException {
boolean isEqual = false;
if (o1 == o2) {
isEqual = true;
}
if (null == o1 || null == o2) {
isEqual = false;
} else {
isEqual = o1.equals(o2);
}
return isEqual;
//for this to work correctly the equals()
//method must be implemented correctly by SimNao class
}
@Override
public int hashCode(final Object value) throws HibernateException {
return value.hashCode();
//for this to work correctly the hashCode()
//method must be implemented correctly by Avatar class
}
/**
* Helps hibernate apply certain optimizations for immutable objects
*/
@Override
public boolean isMutable() { false }
public Cardinalidade toByte (Object value ) {
Byte lRet
if (value instanceof Cardinalidade) {
return value.valor
} else {
return null
}
}
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor sessionImplementor, Object owner) {
def result = rs.getByte(names[0])
if (result != null) {
return new Cardinalidade((java.lang.Byte)result)
}
else {return null}
}
/**
* The method writes the property value to the JDBC prepared Statement
*
*/
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor sessionImplementor) throws HibernateException, SQLException {
Byte bd = null
Cardinalidade snRet
if (value != null) {
snRet = (Cardinalidade) value;
bd = snRet.valor
st.setByte (index, bd)
} else {
st.setByte(index, null)
}
}
/**
* Method used by Hibernate to handle merging of detached object.
*/
public Object replace(final Object original, final Object target,
final Object owner)
throws HibernateException {
//return original; // if immutable use this
//For mutable types at bare minimum return a deep copy of first argument
return this.deepCopy(original);
}
/**
* Method tells Hibernate which Java class is mapped to this Hibernate Type
*/
public Class returnedClass() {
return Cardinalidade.class;
}
/**
* Method tells Hibernate what SQL columns to use for DDL schema generation.
* using the Hibernate Types leaves Hibernate free to choose actual SQl types
* based on database dialect.
* (Alternatively SQL types can also be used directly)
*/
public int[] sqlTypes() {
SQL_TYPES
}
}
?
Para se registrar, clique aqui.