Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Converter is not called on load operation
Converter is not called on load operation [message #903046] Tue, 21 August 2012 17:53 Go to next message
Lars Drießnack is currently offline Lars DrießnackFriend
Messages: 9
Registered: August 2012
Junior Member
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
Re: Converter is not called on load operation [message #905010 is a reply to message #903046] Wed, 29 August 2012 14:52 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

This is not what converters are for, you are not converting a value, you are initializing it. Instead initialize it in your model/application or using a PrePersist event.


James : Wiki : Book : Blog : Twitter
Previous Topic:Dynamic EclipseLink JPA Clarification
Next Topic:JPA-RS hooks and/or HATEOAS?
Goto Forum:
  


Current Time: Thu Apr 25 01:01:07 GMT 2024

Powered by FUDForum. Page generated in 0.02717 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top