Home » Support » Forum » Entity with java.util.Date column gives ClassCastException in BIRT

Entity with java.util.Date column gives ClassCastException in BIRT

#1

Copied a straightforward entity class from my coleague. Using Eclipse Kepler (Reporting) and stored it in ObjectDB 2.5.3_02. After creating an ObjectDB BIRT DataSource and a DataSet, entered a simple JPQL query to select the fields. Entity looks like this:

package entity;

import java.util.Date;
import java.util.List;

import javax.persistence.*;

/**
* Entity class for a patient
*/
@Entity
public class Patient {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private long id;

    private String name;

    private boolean privacy;

    @Column(name="birthdate")
    @Temporal(value = TemporalType.DATE)
    private Date birthdate;

    /**
     * Constructs a new instance
     */
    public Patient() {
        // empty
    }

    /**
     * Returns the id of this {@link Patient}
     * @return the id
     */
    public long getId() {
        return id;
    }

    /**
     * Sets the id of this {@link Patient}
     * @param id the id to set
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * Returns the name of this {@link Patient}
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name of this {@link Patient}
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Returns the birthdate of this {@link Patient}
     * @return the birthdate
     */
    public Date getBirthdate() {
        return birthdate;
    }

    /**
     * Sets the birthdate of this {@link Patient}
     * @param birthdate the birthdate to set
     */
    public void setBirthdate(Date birthdate) {
        this.birthdate = birthdate;
    }

    /**
     * Returns the privacy indication of this {@link Patient}
     * @return the privacy
     */
    public boolean isPrivacy() {
        return privacy;
    }

    /**
     * Sets the privacy indication of this {@link Patient}
     * @param privacy the privacy to set
     */
    public void setPrivacy(boolean privacy) {
        this.privacy = privacy;
    }

}

Exception on previewing query results:

org.eclipse.birt.data.engine.odaconsumer.OdaDataException: Cannot get the timestamp value column: 3.
    org.eclipse.datatools.connectivity.oda.OdaException ;
    java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Timestamp

at org.eclipse.birt.data.engine.odaconsumer.ExceptionHandler.newException(ExceptionHandler.java:55)

at org.eclipse.birt.data.engine.odaconsumer.ExceptionHandler.throwException(ExceptionHandler.java:108)

at org.eclipse.birt.data.engine.odaconsumer.ExceptionHandler.throwException(ExceptionHandler.java:96)

at org.eclipse.birt.data.engine.odaconsumer.ResultSet.getTimestamp(ResultSet.java:350)

at org.eclipse.birt.data.engine.odaconsumer.ResultSet.fetch(ResultSet.java:189)

at org.eclipse.birt.data.engine.executor.cache.OdiAdapter.fetch(OdiAdapter.java:214)

at org.eclipse.birt.data.engine.executor.cache.RowResultSet.fetch(RowResultSet.java:145)

at org.eclipse.birt.data.engine.executor.cache.RowResultSet.doNext(RowResultSet.java:118)

at org.eclipse.birt.data.engine.executor.cache.RowResultSet.next(RowResultSet.java:96)

at org.eclipse.birt.data.engine.executor.transform.SimpleResultSet$RowResultSetWithResultSetScope.fetch(SimpleResultSet.java:1013)

at org.eclipse.birt.data.engine.executor.cache.RowResultSet.doNext(RowResultSet.java:118)

at org.eclipse.birt.data.engine.executor.cache.RowResultSet.next(RowResultSet.java:96)

at org.eclipse.birt.data.engine.executor.transform.SimpleResultSet.prepareFirstRow(SimpleResultSet.java:319)

at org.eclipse.birt.data.engine.executor.transform.SimpleResultSet.getResultSetIterator(SimpleResultSet.java:338)

at org.eclipse.birt.data.engine.executor.DataSourceQuery.execute(DataSourceQuery.java:1057)

at org.eclipse.birt.data.engine.impl.PreparedOdaDSQuery$OdaDSQueryExecutor.executeOdiQuery(PreparedOdaDSQuery.java:503)

at org.eclipse.birt.data.engine.impl.QueryExecutor.execute(QueryExecutor.java:1208)

at org.eclipse.birt.data.engine.impl.ServiceForQueryResults.executeQuery(ServiceForQueryResults.java:233)

at org.eclipse.birt.data.engine.impl.QueryResults.getResultIterator(QueryResults.java:178)

at org.eclipse.birt.report.engine.api.impl.ExtractionResults.nextResultIterator(ExtractionResults.java:157)

at org.eclipse.birt.report.designer.data.ui.dataset.DataSetPreviewer.preview(DataSetPreviewer.java:69)

at org.eclipse.birt.report.designer.data.ui.dataset.ResultSetPreviewPage$5.run(ResultSetPreviewPage.java:366)

at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)

Caused by: org.eclipse.datatools.connectivity.oda.OdaException ;
    java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Timestamp

at com.objectdb.oda.ResultSet.getTimestamp(ResultSet.java:351)

at org.eclipse.datatools.connectivity.oda.consumer.helper.OdaResultSet.getTimestamp(OdaResultSet.java:658)

at org.eclipse.birt.data.engine.odaconsumer.ResultSet.getTimestamp(ResultSet.java:346)

... 19 more

Caused by: java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Timestamp

at com.objectdb.oda.ResultSet.getTimestamp(ResultSet.java:348)

... 21 more

 

I'd rather not use java.sql.Timestamp in my entity classes. Is this a bug in ObjectDB or BIRT or is there an error in my entity class?

#2

A new version of the ObjectDB-BIRT plugin was just released now, please try it.

If it doesn't help, consider changing your field type to Timestamp, or adding casting to Timestamp in the query.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3

Thanks for the quick reply. It works now with the type java.util.Date, no casting was required for me.


Post Reply

To post a reply and/or subscribe to update notifications - please login