aspose file tools*
The moose likes Object Relational Mapping and the fly likes what is hibernate data type? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "what is hibernate data type?" Watch "what is hibernate data type?" New topic
Author

what is hibernate data type?

Brendon Woodford
Ranch Hand

Joined: Jan 22, 2010
Posts: 53
Hi all


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

Joined: Aug 09, 2005
Posts: 61
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
Greenhorn

Joined: Dec 14, 2010
Posts: 27
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?

Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 200
    
    1

You can use this for a reference

Java Class Attribute Type ---- > Hibernate Type

Integer, int, long short ---- > integer, long, short
char ---- > character
java.math.BigDecimal ---- > big_decimal
float, double ---- > float, double
java.lang.Boolean, boolean ---- >boolean, yes_no, true_false
java.lang.String ---- > string
Very long strings ---- > text
java.util.Date ---- > date, time, timestamp
java.util.Calendar ---- > calendar, calendar_date
java.util.Locale ---- > locale
java.util.TimeZone ---- > timezone
java.util Currency ---- > Currency
java.sql.Clob ---- > clob
java.sql.Blob ---- > blob
Java object ---- > serializable
byte array ---- > binary
java.lang.Class ---- > class
Guy Emerson
Greenhorn

Joined: Dec 14, 2010
Posts: 27


Java Class Attribute Type ---- > Hibernate Type

Integer, int, long short ---- > integer, long, short
char ---- > character
java.math.BigDecimal ---- > big_decimal
float, double ---- > float, double
java.lang.Boolean, boolean ---- >boolean, yes_no, true_false
java.lang.String ---- > string
Very long strings ---- > text
java.util.Date ---- > date, time, timestamp
java.util.Calendar ---- > calendar, calendar_date
java.util.Locale ---- > locale
java.util.TimeZone ---- > timezone
java.util Currency ---- > Currency
java.sql.Clob ---- > clob
java.sql.Blob ---- > blob
Java object ---- > serializable
byte array ---- > binary
java.lang.Class ---- > class


Right Sai Hegde,
But do they mean if I put java types in the the mapping files they will be invariably be converted into the aforementioned hibernate types?

ashwin bhawsar
Ranch Hand

Joined: Mar 16, 2011
Posts: 62

http://www.java2s.com/Code/Java/Hibernate/JavaTypeVSHibernateType.htm

This link gives you the mapping between Java, Hibernate & SQL datatypes
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is hibernate data type?