In the last example we created contact.hbm.xml to map Contact Object to the Contact table in the database. Now let's understand the each component of the mapping file.
To recall here is the content of contact.hbm.xml:
| <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="roseindia.tutorial.hibernate.Contact" table="CONTACT"> <id name="id" type="long" column="ID" > <generator class="assigned"/> </id> <property name="firstName"> <column name="FIRSTNAME" /> </property> <property name="lastName"> <column name="LASTNAME"/> </property> <property name="email"> <column name="EMAIL"/> </property> </class> </hibernate-mapping> |
Hibernate mapping documents are simple xml documents.
Here are important elements of the mapping file:.
id element are:
property elements define standard Java attributes and their
mapping into database schema. The property element supports the
column child element to specify additional properties, such as
the index name on a column or a specific column type. If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Understanding Hibernate O/R Mapping View All Comments
Post your Comment