I am trying to create a JPA class that implements a simple interface:
public interface Task<T> {
public void setData(T data);
public T getData();
public void run();
}
For some reason, I need it to be T datastored in serialized form, so my JPA class needs both JPA recipients / setters and an interface implementation. Obviously, they need to be somehow synchronized.
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class AbstractTask<T extends Serializable> implements Task<T> {
private T data;
private byte[] serializedData;
@Override
@Transient
public T getData() {
return data;
}
@Override
public void setData(T data) {
this.data = data;
}
@Column
@Lob
public byte[] getSerializedData() {
return serializedData;
}
public void setSerializedData(byte[] bytes) {
this.serializedData = bytes;
}
}
What is the right approach for synchronizing these class variables or how to rebuild one from the other? The question is a little broader than serialization / deserialization, and applies to any situation where an object can be uniquely rebuilt from persistent JPA data and vice versa.
source
share