Ram Kumar
Ram Kumar

Reputation: 1

data type exception in hibernate

I have the property in pojo that is of type:

private DateTime updateddate;

Now I have to set it type to hibernate query also please suggest what will be the type.

addScalar("updateddate",Hibernate.DATE)

It is throwing this exception.

org.hibernate.property.BasicPropertyAccessor    IllegalArgumentException in class:  setter method of property: updateddate
2013-08-17 16:41:08.252 ERROR   [NDC=]  [Thread-73] org.hibernate.property.BasicPropertyAccessor    expected type: com.rbsfm.ice.common.date.DateTime, actual value: java.sql.Time

Upvotes: 0

Views: 1173

Answers (1)

superEb
superEb

Reputation: 5673

Since DateTime is your own type, you will either need to:

  1. map the property using a custom UserType (which is basically a Hibernate adapter for converting SQL types to your own POJO types)
  2. change the mapped property to a type that Hibernate understands, like java.util.Date or java.sql.Timestamp
  3. use a combination of the above

Also note that you will need to use Hibernate.TIMESTAMP as your scalar type if you need to preserve the "time" portion of the date-time data (but this assumes you're using one of the standard Java types).

EDIT: To accomplish #1, implement the UserType interface (assuming version 3 from your use of Hibernate.DATE in OP) and map it to your field via something like the following (assuming XML mapping):

<hibernate-mapping>
    <typedef name="dateTimeUserType" class="your.custom.DateTimeUserType"/>
    <class ...>
        <!-- rest of mapping here -->
        <property name="updateddate" type="dateTimeUserType" column="UpdatedDate"/>
    </class>
</hibernate-mapping>

Then you should be able to use the custom type for your scalar as well:

query.addScalar("updateddate", Hibernate.custom(your.custom.DateTimeUserType.class));

Note that these code snippets change slightly for Hibernate 4.x, but the principle is the same.

Upvotes: 1

Related Questions