Sunday, 1 January 2012

Hibernate hbm files and main classes

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.sapient.hibernate.manytomany">

<class name="Company" table="DEMO_COMPANY">
<id name="id" column="ID"/>
<property name="name" column="NAME"/>
<set name="cities" cascade="all" table="COMPANY_CITY">
<key column="COMPANY_ID"/>
<many-to-many class="City" column="CITY_ID"/>
</set>
</class>

<class name="City" table="DEMO_CITY">
<id name="id" column="ID"/>
<property name="name" column="NAME"/>
<set name="companies" inverse="true" table="COMPANY_CITY">
<key column="CITY_ID"/>
<many-to-many class="Company" column="COMPANY_ID"/>
</set>
</class>

</hibernate-mapping><?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.sapient.hibernate.compositekey">

<class name="Person" table="DEMO_PERSON">
<composite-id>
<key-property name="firstName" column="FIRST_NAME"/>
<key-property name="lastName" column="LAST_NAME"/>
</composite-id>
<property name="age" column="AGE"/>
</class>

</hibernate-mapping><?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 package="com.sapient.hibernate.inheritence">
<class name="Employee" table="EMPLOYEE">
<id name="id" column="ID"/>
<property name="name" column="NAME"/>
<property name="employeeId" column="EMPLOYEE_ID"/>

<union-subclass name="Developer" table="DEVELOPER">
<property name="language" column="PRG_LANGUAGE"/>
</union-subclass>
<union-subclass name="Manager" table="MANAGER">
<property name="project" column="PROJECT"/>
</union-subclass>
</class>

</hibernate-mapping><?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 package="com.sapient.hibernate.inheritence">

<class name="Employee" table="EMPLOYEE" discriminator-value="EMP">
<id name="id" column="id"/>
<discriminator column="EMP_TYPE" type="string"/>
<property name="name" column="NAME"/>
<property name="employeeId" column="EMPLOYEE_ID"/>


<subclass name="Developer" discriminator-value="DEV" >
<property name="language" column="PRG_LANGUAGE"/>
</subclass>
<subclass name="Manager" discriminator-value="MGR">
<property name="project" column="PROJECT"/>
</subclass>
</class>

</hibernate-mapping><?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 package="com.sapient.hibernate.inheritence">
<class name="Employee" table="EMPLOYEE">
<id name="id" column="ID"/>
<property name="name" column="NAME"/>
<property name="employeeId" column="EMPLOYEE_ID"/>

<joined-subclass name="Developer" table="DEVELOPER">
<key column="EMPLOYEE_ID"></key>
<property name="language" column="PRG_LANGUAGE"/>
</joined-subclass>
<joined-subclass name="Manager" table="MANAGER">
<key column="EMPLOYEE_ID"></key>
<property name="project" column="PROJECT"/>
</joined-subclass>
</class>

</hibernate-mapping><?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.sapient.hibernate.onetoone">

<class name="Trainer" table="DEMO_TRAINER">
<id name="id" column="ID"/>
<property name="name" column="NAME"/>
<many-to-one
name="laptop"
column="LAPTOP_ID"
unique="true"
not-null="true"
cascade="all"/>
</class>

<class name="Laptop" table="DEMO_LAPTOP">
<id name="id" column="ID"/>
<property name="name" column="NAME"/>
</class>

</hibernate-mapping>Dear All,

Please add the attached files to your project as discussed.

Thanks and Regards,
Vivek Mehta

No comments:

Post a Comment