Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Another converter-bug

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].
 
I've filed a bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=412384 with a complete testcase, just unzip it and run "mvn install".
 
Any work-arounds?
 
Thanks.
 
--
Andreas Joseph Krogh <andreak@xxxxxxxxxxxx>      mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc

Back to the top