what is hibernate data type?

It would be great to have a discussion on Hibernate datatype.
What are they? and Why are they required? Where do we use them?

Thanks all

Reddy Prashanth

Ranch Hand

Posts: 61

posted 5 years ago

Hi,

I am not an expert in hibernate but I can give you an overview to start the discussion :-)

Hibernate is an ORM framework. It will map your java objects to database relations. Each database supports its own set of data types. In java , the properties can be of any type from primitives (int, long) to Date, String ...etc. While persisting the java object in the database, hibernate has to know which datatype (DB datatype) should be used for a particular column (like varchar, int..etc).

Hibernate datatype acts as a bridge between java types and DB datatypes. Based on the database dialect , it will choose the correct datatype while creating the tables.
We use hibernate datatypes while creating hibernate mapping files (*.hbm.xml). For example, in the below code snippet, the type="string" is a hibernate type. (not that is all small , unlike java String type). Based on database we use, hibernate will map this "name" property to varchar or something similar.

Guy Emerson

Ranch Hand

Posts: 41

posted 5 years ago

Right Mr. Reddy Prashanth. But what if i change the type of your User class id as int which is a java type or for that matter if i type of property name as String in the following mapping file.
I don't think the Hibernate system would show any error .Why so?