Hi,
I'm trying to generate a value of an entity while persisting it (insertedAt Date). The converter works fine and generates the value but when I'm loading the entity the value of insertedAt is allways null. On database the value exists.
I debugged everything and it just seems that the converter is not called while the process of loading something from the database. The whole field is not loaded.
Entity:
@MappedSuperclass
public abstract class BaseObject implements Serializable {
private static final long serialVersionUID = -1387727537841488003L;
...
@Column(nullable = false)
@Converter(name = "insertedAtConverter", converterClass = ....InsertedAtConverter.class)
@Convert("insertedAtConverter")
private DateTime insertedAt;
...
Converter:
public class InsertedAtConverter implements Converter {
private static Logger logger = Logger.getLogger(InsertedAtConverter.class);
private static final long serialVersionUID = -5174445313301568350L;
@Override
public Object convertObjectValueToDataValue(Object objectValue, Session arg1) {
logger.debug("InsertedAtConverter called.");
if (objectValue == null) {
return DateTime.now().toString();
} else if (objectValue instanceof DateTime) {
return ((DateTime) objectValue).toString();
} else
throw new IllegalStateException("Converstion exception, value is not of org.joda.time.DateTime type or null.");
}
@Override
public Object convertDataValueToObjectValue(Object dataValue, Session arg1) {
logger.debug("DateTimeConverter called.");
if (dataValue instanceof String)
return DateTime.parse((String) dataValue);
else
throw new IllegalStateException("Converstion exception, value is not of String type.");
}
@Override
public void initialize(DatabaseMapping arg0, Session arg1) {
}
@Override
public boolean isMutable() {
return false;
}
}
Any suggestions?
kind regars,
Lars