Java Reference
In-Depth Information
Hibernate 3 Type
Corresponding Java Type
big_decimal
java.math.BigDecimal
big_integer
java.math.BigInteger
locale
java.util.Locale
timezone
java.util.TimeZone
currency
java.util.Currency
class
java.lang.Class
binary
byte[]
text
java.lang.String
serializable
java.io.Serializable
clob
java.sql.Clob
blob
java.sql.Blob
In addition to these standard types, you can create your own. Your user type class should
implement either the org.hibernate.usertype.UserType interface or the org.hibernate.
usertype.CompositeUserType interface. Once implemented, a custom type can behave iden-
tically to the standard types; though depending on your requirements, it may be necessary to
specify multiple column names to contain its values, or to provide initialization parameters
for your implementation.
For one-off cases, we recommend that you use components—these have similar behavior,
but they can be “created” in the mapping file without needing to write Hibernate-specific
code. Unless you propose to make substantial use of a custom type throughout your applica-
tion, it will not be worth the effort. We do not discuss this feature further in this topic.
The Anatomy of a Mapping File
A mapping file is a normal XML file. It is validated against a DTD, which can be downloaded
from http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd . You can also look
through the annotated version at http://hibernatebook.com .
The terminology used in the naming of elements and attributes is somewhat confusing at
first because it is the point of contact between the jargon of the object-oriented and relational
worlds.
The <hibernate-mapping> Element
The root element of any mapping file is <hibernate-mapping> . As the top-level element, its
attributes mostly define default behaviors and settings to apply to the child elements (see
Table 7-2).
Search WWH ::




Custom Search