One thing to try would be to add a descriptor customizer. In it you
would set a new converter on the mapping with the
correct field/attribute classfications.
e.g. mapping.setConverter(new ConverterClass(CustomOption<DateTime>.class.getName(), false,
Timestamp.class.getName(), false));
Information on configuring a descriptor
customizer is
here:
http://wiki.eclipse.org/Configuring_a_Descriptor_%28ELUG%29#Configuring_a_Descriptor_Customizer_Class
Cheers,
Guy
On 05/07/2013 6:01 AM, Andreas Joseph
Krogh wrote:
Hi.
I have this converter:
@Converter
public class OptionalJodaDateTimeConverter implements AttributeConverter<CustomOption<DateTime>, Timestamp> {
@Override
public Timestamp convertToDatabaseColumn(CustomOption<DateTime> attribute) {
if (attribute.isNone()) return null;
else return new Timestamp(attribute.some().getMillis());
}
@Override
public CustomOption<DateTime> convertToEntityAttribute(Timestamp dbData) {
if (dbData == null) return CustomOption.none();
else return CustomOption.some(new DateTime(dbData.getTime()));
}
}
And this mapping:
@Entity
@Table(name = "car")
public class Car {
public Car() {
}
public Car(String model, DateTime modified) {
this.model = model;
this.modified = CustomOption.some(modified);
}
@Id
@Column(name = "model", nullable = false)
private String model = null;
@Column(name = "modified")
@Convert(converter = OptionalJodaDateTimeConverter.class)
private CustomOption<DateTime> modified = CustomOption.none();
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public CustomOption<DateTime> getModified() {
return modified;
}
public void setModified(CustomOption<DateTime> modified) {
this.modified = modified;
}
}
And EL fails generating the correct column-type:
CREATE TABLE car (model VARCHAR(255) NOT NULL, modified VARCHAR(255),
PRIMARY KEY (model))
And fails at runtime:
[EL Warning]: 2013-07-05
11:48:53.517--UnitOfWork(358623257)--Thread(Thread[main,5,main])--Local
Exception Stack:
Exception [EclipseLink-3002] (Eclipse Persistence Services -
2.5.0.v20130507-3faac2b):
org.eclipse.persistence.exceptions.ConversionException
Exception Description: The object [7/5/13 11:48 AM], of
class [class java.sql.Timestamp], from mapping
[org.eclipse.persistence.mappings.DirectToFieldMapping[modified-->car.modified]]
with descriptor
[RelationalDescriptor(no.officenet.example.eclipselink.autoconvert.Car
--> [DatabaseTable(car)])], could not be converted to
[class org.joda.time.DateTime].
Any work-arounds?
Thanks.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
--

Guy Pelletier
ORACLE Canada,
45 O'Connor Street
Suite 400
Ottawa, Ontario
Canada K1P 1A4
Oracle is committed to developing practices
and products that help protect the environment
|