Hibernate Mappings¶
- Hibernate Mappings
Hibernate mapping files are configuration files used by Hibernate to link each property from a DMO to a specific database column. These files are generated during the M0 conversion phase using information from both permanent database files and temporary tables. The input of the Hibernate mapping files are the generated DMO files along with the table definitions from .df
files, for permanent databases, or CREATE TEMP-TABLE
statements, for temporary tables.
The output of Hibernate mapping files generation is a set of .hbm.xml
files, one for each DMO. These files are stored in the same package as the DMO implementation classes. For example, for the simple
database and the BookImpl
DMO implementation, if the DMO implementation class is stored in the dmo/simple/impl/BookImpl.java
file, then the Hibernate mapping file will be found in the dmo/simple/impl/BookImpl.hbm.xml
file.
The generated Hibernate mapping files are structured mainly around classes and properties, being oriented on DMO declarations and not table declarations.
The following table explains the structure of a generated mapping file. This is a simplified description of the Hibernate mapping files structure, including only the elements and attributes generated by the conversion process.
Element name | Description | Attributes |
||||
---|---|---|---|---|---|---|
hibernate-mapping | The root element. | package - this package name of the DMO implementation classes. |
||||
typedef+ | An element of this type will be emitted for each custom value type. | class - the implementation class of the custom user type.name - the name of the custom user type. |
||||
class | The DMO implementation class name. | name - The fully qualified Java class name of the persistent class. table - the name of the database table. |
||||
cache | This element specifies the caching strategy. | usage - specifies a cache concurrency strategy |
||||
id | Mapped classes must declare the primary key column of the database table. This element defines the mapping from that property to the primary key column. | column - The name of the primary key column.name - The name of the identifier property.type - A name that indicates the Hibernate type. |
||||
generator | This child element names a Java class used to generate unique identifiers for instances of the persistent class. |
class - specify the implementation class or a shortcut name of one of the default impementations. The value assigned lets the application to assign an identifier to the object before save() is called. This is the default strategy. |
||||
property+ | This element declares a persistent, JavaBean style property of the class. | column - the name of the mapped database table column. This may also be specified by nested <column> element(s).name - the name of the property, with an initial lowercase letter.type - a name that indicates the Hibernate type.not-null - enable the DDL generation of a nullability constraint for the columns.precision - the precision in case of a decimal data typescale - the scale of data in case of a decimal data type |
||||
list+ | This element specify a collection of values. It is used by FWD to implement extent fields using secondary tables. There will be a list element for each unique extent value. | name - the collection property nametable - the name of the collection tableaccess - The strategy Hibernate should use for accessing this property. Specifying the field value for this attribute will bypass the get/set pair and the field will be accessed directly, using reflection.cascade - enable operations to cascade to child entitieslazy - enable lazy initialization |
||||
cache | This element specifies the caching strategy. | usage - specifies a cache concurrency strategy |
||||
key | This element defines the foreign key in the joined table, that references the primary key of the original table. | N/A |
||||
column+ | This element specify the foreign key column. | name - the name of the foreign key columnindex - the name of the index for this column |
||||
index | This element specify the column used as index for the collection. | column - the index column. |
||||
composite-element | This element specify the collection contained type. | class - the name of the class |
||||
property+ | This element declares a persistent, JavaBean style property of the class. | column - the name of the mapped database table column.name - the name of the property, with an initial lowercase letter.type - a name that indicates the Hibernate type. |
Table 1. The structure of a generated Hibernate mapping file.
Please refer to Hibernate documentation for a complete description of the syntax of the XML mapping files.
Common Elements¶
Each Hibernate mapping file generated during the conversion process includes standards elements. This elements are not dependent on the schema definition but are related to the .hbm.xml file format and the common custom user data types used to map the FWD data types.
Common XML Declarations and Elements¶
This common XML declarations and elements are the DOCTYPE
definition and the hibernate-mapping
element. The DOCTYPE
declaration defines the document structure with a list of legal elements and attributes that are specific to Hibernate mapping files. Each mapping file will start with the xml
and DOCTYPE
declarations:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
Following the declaration header of the file there is the hibernate-mapping
root element. This element contains the package attribute that specify the location of the DMO implementation classes. For example, for the simple
database and the root package name com.foo.bar
, the hibernate-mapping element will be:
<hibernate-mapping package="com.foo.bar.dmo.simple.impl"> ... <hibernate-mapping/>
The root element will have as children typedef
elements defining the FWD wrapper types and a class
element that includes class and property definitions.
TYPEDEF Elements¶
The typedef element assign a name to a custom user type. As the Progress data types are mapped to FWD wrapper types, the typedef specifications are used to define this wrapper types in the mapping file, giving them a shorter name. Although this types could be used directly in mapping file element attributes, using this shorter names increase the lisibility of the file.
<!-- Typedefs for FWD wrapper types --> <typedef class="com.goldencode.p2j.persist.type.IntegerUserType" name="p2j_integer"/> <typedef class="com.goldencode.p2j.persist.type.DecimalUserType" name="p2j_decimal"/> <typedef class="com.goldencode.p2j.persist.type.LogicalUserType" name="p2j_logical"/> <typedef class="com.goldencode.p2j.persist.type.CharacterUserType" name="p2j_character"/> <typedef class="com.goldencode.p2j.persist.type.DateUserType" name="p2j_date"/> <typedef class="com.goldencode.p2j.persist.type.RawUserType" name="p2j_raw"/> <typedef class="com.goldencode.p2j.persist.type.RowIDUserType" name="p2j_rowid"/>
The mapping between Progress data types and FWD wrapper types is presented in the following table:
Progress 4GL data type | Hibernate mapping file user defined type |
---|---|
integer | p2j_integer |
decimal | p2j_decimal |
logical | p2j_logical |
character | p2j_character |
date | p2j_date |
raw | p2j_raw |
rowid | p2j_rowid |
Progress Schema Definition Mapping¶
The input source for generating a Hibernate mapping file is the DMO corresponding to a Progress table. Because a DMO are generated following the corresponding Progress table structure there will be a mapping between the content of the original input (.df
file or define temp-table
statement) and the generated .hbm.xml
file. In the following sections the corresponding syntax between the original Progress table definitions and the resulting Hibernate mapping files will be presented.
Table Definition Conversion for Persistent Tables¶
Each Progress table definition has a corresponding class element in the .hbm.xml
file. For a persistent table the following table definition syntax elements will be mapped by the conversion process to XML elements or attributes in the Hibernate mapping file:
.df Schema Syntax | Hibernate mapping file |
---|---|
ADD TABLE "table_name" TYPE symbol |
<class name="TableNameImpl" table="table_name"> ... </class> |
DESCRIPTION "table_description" |
<!-- table_description --> XML comment |
Some of the schema syntax elements referring to table definition do not have a correspondent entry in .hmb.xml
file. This elements are listed below:
.df Schema Syntax | Description |
---|---|
AREA |
Not supported. |
CAN-CREATE |
Not supported. |
CAN-DELETE |
Not supported. |
CAN-DUMP |
Not supported. |
CAN-LOAD |
Not supported. |
CAN-READ |
Not supported. |
CAN-WRITE |
Not supported. |
DUMP-NAME |
No element generated in .hbm.xml file. |
FROZEN |
Not supported. |
HIDDEN |
Not supported. |
LABEL |
Not supported. |
TABLE-TRIGGER type_string (OVERRIDE | NO-OVERRIDE) PROC proc_name CRC logical_string |
Not supported. |
VALEXP |
Not supported. |
VALMSG |
Not supported. |
Persistent table definition example:
ADD TABLE "book" AREA "Schema Area" DESCRIPTION "Book Catalog" DUMP-NAME "book"
Generated elements in the Hibernate mapping file:
<!-- Book Catalog --> <class name="BookImpl" table="book"> ... </class>
Table Definition Conversion for Temporary Tables¶
For a temporary table the conversion process will generate the following elements in the Hibernate mapping file:
Temporary table definition | Hibernate mapping file |
---|---|
define temp-table temp_table_name |
<class name="TempRecord1Impl" table="temp_table_name"> ... </class> |
define work-table work_table_name |
<class name="TempRecord1Impl" table="work_table_name"> ... </class> |
LIKE table_name |
All definitions are copied from the table_name into the temp-table and converted as if it was hard coded into the DEFINE TEMP-TABLE statement. |
The following syntax elements are not supported or do not have a corresponding element in the mapping file.
Temporary table definition | Description |
---|---|
BEFORE-TABLE |
Not supported. |
NAMESPACE-PREFIX |
Not supported. |
NAMESPACE-URI |
Not supported. |
NEW GLOBAL SHARED |
No element generated in .hbm.xml file. |
NEW SHARED |
No element generated in .hbm.xml file. |
NO-UNDO |
No element generated in .hbm.xml file. |
PRIVATE |
Not supported. |
PROTECTED |
Not supported. |
RCODE-INFORMATION |
Not supported. |
REFERENCE-ONLY |
Not supported. |
SHARED |
No element generated in .hbm.xml file. |
VALIDATE |
No element generated in .hbm.xml file. |
Temporary table definition example:
/* tbook temporary table */ define temp-table tbook
Generated elements in the Hibernate mapping file:
<!-- TempRecord1 class --> <class name="TempRecord1Impl" table="tt1"> ... </class>
Field Definition Conversion for Persistent Tables¶
For a persistent table the following field definition properties will be mapped by the conversion process to elements or attributes in the Hibernate mapping file:
.df Schema Syntax | Hibernate mapping file |
---|---|
ADD FIELD "field_name" OF "table_name" |
<property name=fieldName" column="field_name"> ... </property> |
AS data_type |
type="p2j_data_type" attribute of the property element. See the section named TYPEDEF Elements for details on the associated mappings that are supported. |
DECIMALS num |
precision="50" scale="num" attribute of property element |
DESCRIPTION field_description |
<!-- field_description --> XML comment for the property element. |
EXTENT num |
<!-- List of composite elements --> <list access="field" cascade="evict" lazy="true" name="compositeNUM" table="table_name__NUM"> ... <key> <column index="table_name__NUM_fkey" name="parent__id"/> </key> <index column="list__index"/> <composite-element class="TableNameImpl$CompositeNUM"> ... </composite-element> </list> |
LABEL "Field_name label" |
<!-- Field_name label --> XML comment for the property element. If a description is also present then both texts will be included in the XML comment:<!-- Field_name label; Field_name description --> |
MANDATORY |
not-null="true" attribute of the property element. |
The following field definition properties do not have a corresponding element in the .hbm.xml
file:
.df Schema Syntax | Description |
---|---|
CASE-SENSITIVE |
No element generated in the .hbm.xml file. |
COLUMN-LABEL |
No element generated in the .hbm.xml file. |
FIELD-TRIGGER type_string (OVERRIDE | NO-OVERRIDE) PROC proc_name CRC logical_string |
Not supported. |
FORMAT expression |
No element generated in the .hbm.xml file. |
HELP |
No element generated in the .hbm.xml file. |
INTIAL |
No element generated in the .hbm.xml file. |
LENGTH |
Not supported. |
LOB-AREA string |
Not supported. |
LOB-BYTES |
Not supported. |
LOB-SIZE |
Not supported. |
MAX-WIDTH |
Not supported. |
ORDER number |
No element generated in the .hbm.xml file. |
POSITION number |
Not supported. |
SQL-WIDTH |
Not supported. |
VALEXP |
No element generated in the .hbm.xml file. |
VALMSG |
No element generated in the .hbm.xml file. |
VIEW-AS phrase |
No element generated in the .hbm.xml file. |
Example: Conversion of a character
field definition for a permanent table.
ADD FIELD "publisher" OF "book" AS character FORMAT "x(20)" INITIAL "" DESCRIPTION "The name of the publisher" LABEL "Publisher" SQL-WIDTH 40 COLUMN-LABEL "Publisher" ORDER 30
Generated elements in the Hibernate mapping file:
<!-- Publisher; The name of the publisher --> <property column="publisher" name="publisher" type="p2j_character"/>
Example: Conversion of an integer
field definition for a permanent table.
ADD FIELD "book-id" OF "book" AS integer FORMAT "99999999" INITIAL "0" LABEL "Book Identifier" SQL-WIDTH 4 COLUMN-LABEL "Book ID" ORDER 10 MANDATORY
Generated elements in the Hibernate mapping file:
<!-- Book Identifier --> <property column="book_id" name="bookId" not-null="true" type="p2j_integer"/>
Example: Conversion of a decimal
field definition for a permanent table.
ADD FIELD "cost" OF "book" AS decimal FORMAT "->>,>>9.99" INITIAL "0" LABEL "Cost" SQL-WIDTH 17 COLUMN-LABEL "Cost" VALEXP "cost > 0" VALMSG "Cost must be greater than 0." DECIMALS 2 ORDER 60
Generated elements in the Hibernate mapping file:
<!-- Cost --> <property column="cost" name="cost" precision="50" scale="2" type="p2j_decimal"/>
Example: Conversion of a date
field definition for a permanent table.
ADD FIELD "pub-date" OF "book" AS date FORMAT "99/99/9999" INITIAL ? LABEL "Publish Date" SQL-WIDTH 4 COLUMN-LABEL "Publish Date" ORDER 70
Generated elements in the Hibernate mapping file:
<!-- Publish Date --> <property column="pub_date" name="pubDate" type="p2j_date"/>
Example: Conversion of a logical
field definition for a permanent table.
ADD FIELD "in-print" OF "book" AS logical FORMAT "Yes/No" INITIAL "yes" LABEL "In Print" HELP "Determines if this book is available for purchase." SQL-WIDTH 1 ORDER 110
Generated elements in the Hibernate mapping file:
<!-- In Print --> <property column="in_print" name="inPrint" type="p2j_logical"/>
Example: Conversion of a raw
field definition for a permanent table.
ADD FIELD "abstract" OF "book" AS raw FORMAT "x(2000)" INITIAL "?" LABEL "Abstract" HELP "A summary of the contents" SQL-WIDTH 2000 CASE-SENSITIVE ORDER 120
Generated elements in the Hibernate mapping file:
<!-- Abstract --> <property column="abstract" name="abstract_" type="p2j_raw"/>
Example: Conversion of extent
fields definition for a permanent table.
ADD FIELD "author-id" OF "book" AS integer EXTENT 10 LABEL "Author ID" ORDER 20 ADD FIELD "author-ext-id" OF "book" AS integer EXTENT 10 LABEL "Ext Author ID" ORDER 30 ADD FIELD "old-edition-id" OF "book" AS integer EXTENT 5 LABEL "Old Edition ID" ORDER 40
Generated elements in the Hibernate mapping file:
<!-- List of composite elements --> <list access="field" cascade="evict" lazy="true" name="composite5" table="book__5"> <!-- Second level cache --> <cache usage="nonstrict-read-write"/> <key> <column index="book__5_fkey" name="parent__id"/> </key> <index column="list__index"/> <composite-element class="BookImpl$Composite5"> <!-- Old Edition ID --> <property column="old_edition_id" name="oldEditionId" type="p2j_integer"/> </composite-element> </list> <!-- List of composite elements --> <list access="field" cascade="evict" lazy="true" name="composite10" table="book__10"> <!-- Second level cache --> <cache usage="nonstrict-read-write"/> <key> <column index="book__10_fkey" name="parent__id"/> </key> <index column="list__index"/> <composite-element class="BookImpl$Composite10"> <!-- Author ID --> <property column="author_id" name="authorId" type="p2j_integer"/> <!-- Ext Author ID --> <property column="author_ext_id" name="authorExtId" type="p2j_integer"/> </composite-element> </list>
Note that three extent fields will be mapped to only two secondary tables (book__5
and book__10
) because two of this fields have the same extent value.
Field Definition Conversion for Temporary Tables¶
For a temporary table the following field definition properties will be mapped by the conversion process to elements or attributes in the Hibernate mapping file:
Temporary table definition | Hibernate mapping file |
---|---|
AS data_type |
type="p2j_data_type" attribute of the property element. See the section named TYPEDEF Elements for details on the associated mappings that are supported. |
DECIMALS num |
precision="50" scale="num" attribute of property element |
DESCRIPTION field_description |
<!-- field_description --> XML comment for the property element. |
EXTENT num |
<!-- List of composite elements --> <list access="field" cascade="evict" lazy="true" name="compositeNUM" table="table_name__NUM"> ... <key> <column index="table_name__NUM_fkey" name="parent__id"/> </key> <index column="list__index"/> <composite-element class="TableNameImpl$CompositeNUM"> ... </composite-element> </list> |
[FIELD] "field_name" |
<property name="fieldName" column="field_name"> ... </property> |
LABEL "Field_name label" |
<!-- Field_name label --> XML comment for the property element. If a description is also present then both texts will be included in the XML comment:<!-- Field_name label; Field_name description --> |
LIKE field_name |
The definition is copied from the field_name into the temp-table and converted as if it was hard coded into the DEFINE TEMP-TABLE statement. |
MANDATORY |
not-null="true" attribute of the property element. |
The following field definition properties do not have a correspondent in the Hibernate mapping file:
.df Schema Syntax | Description |
---|---|
BGCOLOR expression |
Not supported. |
COLUMN-CODEPAGE cp_name |
Not supported. |
COLUMN-LABEL label |
No element generated in the .hbm.xml file. |
DCOLOR expression |
No element generated in the .hbm.xml file. |
FGCOLOR |
Not supported. |
FONT expression |
Not supported. |
FORMAT expression |
No element generated in the .hbm.xml file. |
HELP |
No element generated in the .hbm.xml file. |
INTIAL |
No element generated in the .hbm.xml file. |
MOUSE-POINTER expression |
Not supported. |
[NOT] CASE-SENSITIVE |
No element generated in the .hbm.xml file. |
PFCOLOR |
No element generated in the .hbm.xml file. |
TTCODEPAGE |
Not supported. |
VIEW-AS phrase |
No element generated in the .hbm.xml file. |
XML-DATA-TYPE text |
Not supported. |
XML-NODE-TYPE text |
Not supported. |
Example: Conversion of field definitions for a temporary table.
field book-id as integer format "99999999" field book-title as character format "x(35)" field publisher as character format "x(20)" field isbn as character format "x(15)" field on-hand-qty as integer format "99999" field cost as decimal format "->>,>>9.99" decimals 2 field pub-date as date format "99/99/9999" field author-id as integer format "9999999" extent 10 field sold-qty as integer format ">,>>9" field price as decimal format "->>,>>9.99" decimals 2 field in-print as logical format "Yes/No"
Hibernate mapping file elements:
<property column="book_id" name="bookId" type="p2j_integer"/> <property column="book_title" name="bookTitle" type="p2j_character"/> <property column="publisher" name="publisher" type="p2j_character"/> <property column="isbn" name="isbn" type="p2j_character"/> <property column="on_hand_qty" name="onHandQty" type="p2j_integer"/> <property column="cost" name="cost" precision="50" scale="2" type="p2j_decimal"/> <property column="pub_date" name="pubDate" type="p2j_date"/> <property column="sold_qty" name="soldQty" type="p2j_integer"/> <property column="price" name="price" precision="50" scale="2" type="p2j_decimal"/> <property column="in_print" name="inPrint" type="p2j_logical"/> <!-- List of composite elements --> <list access="field" cascade="evict" lazy="true" name="composite10" table="tt1__10"> <!-- Second level cache --> <cache usage="nonstrict-read-write"/> <key> <column index="tt1__10_fkey" name="parent__id"/> </key> <index column="list__index"/> <composite-element class="TempRecord1Impl$Composite10"> <property column="author_id" name="authorId" type="p2j_integer"/> </composite-element> </list>
Hibernate Associations for Foreign Relations¶
The Hibernate mapping file generated by the conversion process for a table could also include foreign key constraints. This elements of the mapping file will be emitted only if the foreign-keys
global parameter of p2j.cfg.xml
file is set to true and the 4GL code contains natural joins. Please see the DDL with Foreign-Keys Enabled and Foreign Relations sections of this chapter for more informations about natural joins and foreign keys.
Currently the conversion process will generate the association related elements in the mapping file for the following types of relations: one-to-one, one-to-many and many-to-one relations.
One to One Relations¶
If there is a natural join between two tables and in both tables the indexes for the field(s) defining the relation have the same set of fields and are both uniques, than the relation between the tables is a one-to-one relation. The set of fields in the common, unique index form the primary/foreign key relation.
The conversion process will generate a one-to-one association, the result being that both .hbm.xml
files of the the tables will contain an <one-to-one />
element.
For the first table the <one-to-one />
element with the following attributes will be added :
<!-- Association with Second (i.e., table second) --> <one-to-one class="SecondImpl" name="secondRecord" property-ref="firstRecord"/>
For the second table the <one-to-one />
element with the following attributes will be added :
<!-- Association with First (i.e., table first) --> <one-to-one class="FirstImpl" name="firstRecord" property-ref="secondRecord"/>
The attributes of the <one-to-one />
element are presented in the following table:
Attribute | Description |
---|---|
class="class_name" |
The name of the associated class. This attribute specify the DMO Implementation class corresponding to the table being in relation with. |
name="property_name" |
The name of the property with the format <DMO_name>Record |
property-ref="property_ref_name" |
The name of the property of the associated class that is joined to the primary key of this class. |
Example: Conversion example of a one-to-one relation using temporary tables.
define temp-table tbook field book-id as integer field book-title as character field publisher-id as integer index book-id is unique primary book-id ascending index publisher-id publisher-id index book-title is unique book-title. define temp-table ttitle field book-title as character field original-title as character index book-title is unique primary book-title. for each tbook, each ttitle of tbook: display tbook.book-title ttitle.original-title. end.
The Hibernate mapping file corresponding to the tbook
table will contain the following elements:
<!-- Association with TempRecord2 (i.e., table tt2) --> <one-to-one class="TempRecord2Impl" name="tempRecord2Record" property-ref="tempRecord1Record"/>
The Hibernate mapping file corresponding to the ttitle
table will contain the following elements:
<!-- Association with TempRecord1 (i.e., table tt1) --> <one-to-one class="TempRecord1Impl" name="tempRecord1Record" property-ref="tempRecord2Record"/>
Note that both tables contain the book-title
unique index with the same set of fields.
Example: Conversion example of a one-to-one relation using permanent tables.
For two permanent tables, book
and title
, with the same fields and indexes as the temporary tables from the example above the generated elements in the Hibernate mapping files will be:
<!-- Title Schema --> <class name="TitleImpl" table="title"> ... <!-- Association with Book (i.e., table book) --> <one-to-one class="BookImpl" name="bookRecord" property-ref="titleRecord"/> </class>
<!-- Book Catalog --> <class name="BookImpl" table="book"> ... <!-- Association with Title (i.e., table title) --> <one-to-one class="TitleImpl" name="titleRecord" property-ref="bookRecord"/> </class>
One to Many and Many to One Relations¶
If there is a natural join between two tables and only in one of the two tables the index for the field(s) defining the relation is unique, than the relation between the tables is a one-to-many relation. The table defining the unique index will be the parent table and the other will be the child table.
The conversion process will generate bidirectional associations, the result being that both .hbm.xml
files corresponding to the parent and child table will contain an element related to the foreign key constraint. For the parent table the <many-to-one />
element will be generated in the .hbm.xml
file and for the child table the <one-to-many />
element.
For the child table a special <many-to-one />
element with the following attributes will be added :
<!-- Foreign relation to parentRecord (i.e., table parent) --> <many-to-one class="ParentImpl" column="parent__fk" index="idx_child__1234567890123" name="parentRecord"/>
The attributes of this element are presented in the following table:
Attribute | Description |
---|---|
class="ParentImpl" |
This attribute specify the DMO Implementation class corresponding to the parent table. |
column="parent__fk" |
The field name of the foreign key column referencing the parent table. |
index="idx_child__1234567890123" |
The name of the index of the foreign key column with the format : idx_<child_table>__<unique_ID> |
name="parentRecord" |
The name of the property. |
For the parent table a <set />
element the with the following child elements and attributes will be added :
<!-- Association with Child (i.e., table child) --> <set inverse="true" name="childSet"> <key column="parent__fk"/> <one-to-many class="ChildImpl"/> </set>
attribute | Description |
---|---|
inverse="true|false" |
This inverse atribute controls if the parent or the child is responsible for maintaining the relation. The inverse=”true” will set the child as being responsible for maintaining the association. |
name="childSet" |
The name of the property. |
column="parent__fk" |
The field name of the foreign key column from the child table referencing the parent table. . |
class="ChildImpl" |
This attribute specify the DMO Implementation class corresponding to the child table. |
Example 1: One-to-many relation
In the following example the tpublisher
is the parent table and tbook
is the child table.
define temp-table tbook field book-id as integer field book-title as character field publisher-id as integer index book-id is unique primary book-id ascending index publisher-id publisher-id. define temp-table tpublisher field publisher-id as integer field name as integer index publisher-id is unique primary publisher-id. for each tpublisher, each tbook of tpublisher : display tpublisher. display tbook. end.
For the tbook
table the conversion process will generate the TempRecord1Impl
DMO implementation and the runtime temporary table name will be tt1
. The TempRecord1Impl.hbm.xml
file generated for the tbook
table will include the following elements:
<class name="TempRecord1Impl" table="tt1"> ... <!-- Foreign relation to tempRecord2Record (i.e., table tt2) --> <many-to-one class="TempRecord2Impl" column="tt2__fk" index="idx_tt1__1234567890123" name="tempRecord2Record"/> </class>
For the tpublisher
table the conversion process will generate the TempRecord2Impl
DMO implementation and the runtime temporary table name will be tt2
. The TempRecord2Impl.hbm.xml
file generated for the tpublisher
table will include the following elements:
<class name="TempRecord1Impl" table="tt1"> ... <!-- Association with TempRecord1 (i.e., table tt1) --> <set inverse="true" name="tempRecord1Set"> <key column="tt2__fk"/> <one-to-many class="TempRecord1Impl"/> </set> </class>
Example 2: One-to-many relations with an intermediate table.
A many-to-many relation between two tables could be implemented using an intermediate table, the initial many-to-many relation being transformed into two one-to-many relations. In the following example, the many-to-many relation between book and authors(considering that a book may have multiple authors and an author wrote several books) is implemented with the aid of the tbook-author
table.
define temp-table tbook field book-id as integer field book-title as character field publisher-id as integer index book-id is unique primary book-id ascending index publisher-id publisher-id. define temp-table tauthor field author-id as integer field name as character index author-id is primary unique author-id. define temp-table tbook-author field author-id as integer field book-id as integer index book-id book-id index author-id author-id. for each tbook where tbook.book-title = 'FWD Conversion Reference', tbook-author of tbook, tauthor of tbook-author: display tauthor.name. end.
The Hibernate mapping file corresponding to the tbook
table will contain the following elements:
<!-- Association with TempRecord3 (i.e., table tt3) --> <set inverse="true" name="tempRecord3Set"> <key column="tt1__fk"/> <one-to-many class="TempRecord3Impl"/> </set>
The Hibernate mapping file corresponding to the tauthor
table will contain the following elements:
<!-- Association with TempRecord3 (i.e., table tt3) --> <set inverse="true" name="tempRecord3Set"> <key column="tt2__fk"/> <one-to-many class="TempRecord3Impl"/> </set>
The Hibernate mapping file corresponding to the tbook-author
table will contain the following elements defining two many to one relations:
<!-- Foreign relation to tempRecord1Record (i.e., table tt1) --> <many-to-one class="TempRecord1Impl" column="tt1__fk" index="idx_tt3__1234567890111" name="tempRecord1Record"/> <!-- Foreign relation to tempRecord2Record (i.e., table tt2) --> <many-to-one class="TempRecord2Impl" column="tt2__fk" index="idx_tt3__1234567890222" name="tempRecord2Record"/>
For permanent tables the .hbm.xml
file will include the same elements as for temporary tables.
Other Elements¶
The Hibernate mapping file will also include some elements that are not a direct mapping of a table or field definition from in the input .df
file, define temp-table statement or as a result of natural joins. These elements are the surrogate primary key declaration and the cache declaration and generated immediately after the class element.
Example : Other elements of the Hibernate mapping file.
<class name="BookImpl" table="book"> <!-- Second level cache --> <cache usage="nonstrict-read-write"/> <!-- Surrogate primary key --> <id column="id" name="id" type="long"> <generator class="assigned"/> </id> ... </class>
© 2004-2017 Golden Code Development Corporation. ALL RIGHTS RESERVED.