|
Hibernate example source code file (Person.hbm.xml)
The Hibernate Person.hbm.xml source code<?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"> <!-- This mapping demonstrates (1) a table-per-subclass mapping strategy where subclass data is retrieved by sequential select instead of a join (we do NOT recommend you do this, since it is very vulnerable to N+1 problems; users porting applications from TopLink might find this useful for reproducing old behavior) (2) spreading data from a single class across multiple tables (again, we do not recommend you do this; use finer grained classes instead) (3) use of null as a discriminator value (4) recursive associations withing an inheritance tree --> <hibernate-mapping package="org.hibernate.test.join" default-access="field"> <class name="Person" table="person" lazy="true" discriminator-value="null"> <id name="id" column="person_id" unsaved-value="0"> <generator class="native"/> </id> <!-- force is unnecessary, in case we had other unknown discriminator values --> <discriminator column="person_type" type="string" length="1" not-null="false" force="true"/> <property name="name" not-null="true" length="80"/> <property name="sex" not-null="true" update="false"/> <property name="heightInches"> <column name="height_centimeters" not-null="true" read="height_centimeters / 2.54E0" write="? * 2.54E0"/> </property> <join table="address"> <key column="address_id"/> <property name="address"/> <property name="zip"/> <property name="country"/> </join> <subclass name="Employee" lazy="true" discriminator-value="E"> <join table="employee" fetch="select"> <key column="person_id"/> <property name="title" column="`title`" not-null="true" length="20"/> <property name="salary" length="0"/> <many-to-one name="manager"/> </join> </subclass> <subclass name="Customer" lazy="true" discriminator-value="C"> <join table="customer" fetch="select"> <key column="person_id"/> <property name="comments"/> <many-to-one name="salesperson"/> </join> </subclass> <subclass name="User" lazy="true" discriminator-value="U"> <join table="t_user" fetch="select" optional="true"> <key column="person_id"/> <property name="login" column="u_login"/> <property name="passwordExpiryDays"> <column name="pwd_expiry_weeks" read="pwd_expiry_weeks * 7.0E0" write="? / 7.0E0"/> </property> </join> <join table="t_silly" fetch="select" optional="true"> <key column="person_id"/> <property name="silly"/> </join> </subclass> </class> </hibernate-mapping> Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate Person.hbm.xml source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.