In hibernate environment there would be one class_name.hbm.xml file for each entity/object. This file will be used to map an object with the corresponding table in database.
For example - Person.hbm.xml would be used to map the table 'PERSON' in database which stores the Person objects.
Below is a simple example to write hbm.xml file
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="path.to.the.class.package.Person" table="PERSON">
<id name="lastName" type="string" unsaved-value="null" >
<column name="L_NAME" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="firstName" column="F_NAME" type="string"/>
<property name="age" column="AGE" type="integer"/>
<property name="city" column="CITY" type="string"/>
<property name="pinCode" column="PIN" type="integer"/>
</class>
</hibernate-mapping>
To make hibernate to use this file or to load this file in environment you need to specify the property for this in hibernate.cfg.xml as below
<mapping resource="path/to/the/hbmXml/file/Person.hbm.xml">
In next section we will see what is the next thing to learn to start the Hibernate development.
Subscribe to:
Post Comments (Atom)
SpringBoot: Features: SpringApplication
Below are a few SpringBoot features corresponding to SpringApplication StartUp Logging · To add additional logging during startup...
-
There was a requirement in which user should be able to download an excel report from application, make some amendments and upload the exce...
-
I was facing 'java.rmi.NoSuchObjectException: Bean has been deleted' for the stateful bean instance. While reading about the error, ...
-
What Is a WebLogic Server Cluster? A WebLogic Server cluster consists of multiple WebLogic Server server instances running simultaneously an...
No comments:
Post a Comment