views:

35

answers:

1

I have Class CustomDate and that is referred in other class called Test.

public   class CustomDate{
    public String toString(){
       return "20100829"
    }
}
public class Test{
    CustomDate date;
}

In Mapping file of Test

<property name="date" COLUMN="DATE">

I want to save only long value and type should be long type and i should not save date object and string value.long value will be this like:"20100829" actual date:29-08-2010. Because in feature if want compare dates in sql it may create problem, if it is long value, sql compare queries will fine. Do we have any way do it in Hibernate?

+3  A: 

You'll have to implement the UserType interface, and define the behavior of your new type.

<property name="twoStrings" type="com.company.CustomDate" />

Resources :

Related posts :

Colin Hebert
+1 for body of the answer, and the nice layout :)
Pascal Thivent
I totally stole it from polygenelubricants :P
Colin Hebert