Skip to main content

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

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].
 
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


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

--

Oracle
Guy Pelletier

ORACLE Canada, 45 O'Connor Street Suite 400 Ottawa, Ontario Canada K1P 1A4

Green
            Oracle Oracle is committed to developing practices and products that help protect the environment


Back to the top