When ever we are dealing with any DB, we need to take of data representation in Database and language.
Hibernate deals with both using types.
1) Basic value types:
Java Type | Hibernate Type | JDBC Type |
---|---|---|
java.lang.String | org.hibernate.type.StringType | VARCHAR |
java.lang.Character (or char primitive) | org.hibernate.type.CharacterType | CHAR |
java.lang.Boolean (or boolean primitive) | org.hibernate.type.BooleanType | BIT type |
java.lang.Byte | org.hibernate.type.ByteType | JDBC TINYINT |
java.lang.Short | org.hibernate.type.ShortType | JDBC SMALLINT |
java.lang.Integer | org.hibernate.type.IntegerTypes | JDBC INTEGER |
java.lang.Long | org.hibernate.type.LongType | JDBC BIGINT |
java.lang.Float | org.hibernate.type.FloatType | JDBC FLOAT |
java.lang.Double | org.hibernate.type.DoubleType | JDBC DOUBLE |
java.math.BigInteger | org.hibernate.type.BigIntegerType | JDBC NUMERIC |
java.math.BigDecimal | org.hibernate.type.BigDecimalType | JDBC NUMERIC |
java.util.Date or java.sql.Timestamp | org.hibernate.type.TimestampType | JDBC TIMESTAMP |
java.sql.Time | org.hibernate.type.TimeType | JDBC TIME |
java.sql.Date | org.hibernate.type.DateType | JDBC DATE |
java.util.Calendar | org.hibernate.type.CalendarType | JDBC TIMESTAMP |
java.util.Currency | org.hibernate.type.CurrencyType | JDBC VARCHAR |
java.util.Locale | org.hibernate.type.LocaleType | JDBC VARCHAR |
java.util.TimeZone | org.hibernate.type.TimeZoneType | JDBC VARCHAR |
java.net.URL | org.hibernate.type.UrlType | JDBC VARCHAR |
java.lang.Class | org.hibernate.type.ClassType | JDBC VARCHAR |
java.sql.Blob | org.hibernate.type.BlobType | JDBC BLOB |
java.sql.Clob | org.hibernate.type.ClobType | JDBC CLOB |
java.util.UUID | org.hibernate.type.UUIDBinaryType | JDBC BINARY |
java.io.Serializable | org.hibernate.type.SerializableType | JDBC VARBINARY |
2) Composite types: We can have separate classes like address which contains all the address fields And can be used as a object in another Employee Entity using Embedded and Embeddable annotations.
3) Collection Types: We can persist collection using Hibernate where collection can have any hibernate type like:basic,custom etc.
4) Custom Types: We can create our own types like If we want to represent an integer value to varchar column.