Reputation: 1
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
Reputation: 5673
Since DateTime
is your own type, you will either need to:
UserType
(which is basically a Hibernate adapter for converting SQL types to your own POJO types)java.util.Date
or java.sql.Timestamp
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