Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 578

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
ColdFusion ORM
Emp.cfm
<cfscript>
employee = EntityNew("Employee");
employee.setEmployeeName("Dan Watson");
imdata1 = new IMData();
imdata1.setType("IMClient1");
imdata1.setID("msngrId1");
imdata2 = new IMData();
imdata2.setType("IMClient 2");
imdata2.setID("msngrId2");
employee.setIMIDs([imdata1, imdata2]);
EntitySave(employee);
</cfscript>
For more details on component mapping in hibernate, see
Join mapping in a CFC
Join mapping is used to map the properties of one CFC to several tables. In this case, tables are joined using a join
column. For example, consider a case where the Employee and Address tables, are mapped to a single CFC Employees.
Therefore, the
employee.cfc
in Address table. The attributes
in Address table. In this case, table would be
Note: Hibernate uses outer join by default for join fetching. For inner join, use HQL.
Following is a sample employee.cfc
Employee.cfc
<cfcomponent persistent="true">
<cfproperty name="id">
<cfproperty name="name">
<cfproperty name="houseno" column="houseno" table="Address" joincolumn="addressId">
<cfproperty name="street" table="Address" joincolumn="addressId">
<cfproperty name="city" table="Address" joincolumn="addressId">
<cfproperty name="country" table="Address" joincolumn="addressId">
</cfcomponent>
Define the ORM mapping in the Hibernate mapping file
ColdFusion can also use the standard Hibernate Mapping XML file to define the mapping between the object and the
database. You can use both Java classes and CFCs in Hibernate mapping. For a complete description of hibernate
mapping, see www.hibernate.org/hib_docs/reference/en/html/mapping.html.
Note the following points when using Hibernate mapping files.
• The extension of the Hibernate configuration file is *.hbmxml.
• The file is placed in the Application folder.
• The class name must be specified as cfc:<fully qualified name of cfc>. If a package is specified in the hibernate
mapping, then specify the class name as cfc:<name of cfc>.
• The entityname attribute is optional. If you do not specify this attribute, it takes the component name, by default.
For example, for the component artgallery.art, the value of the entityname attribute is "Art", by default.
• The entity name must be unique for an application. If there are two components with the same name (even if they
are in different packages), specify different entity names for each of these components.
has some fields, which are persisted in Employee table and some fields that are persisted
and
should be specified for those fields that need to be persisted
joincolumn
table
and
Address
Last updated 1/20/2012
Component Mapping
in Hibernate Reference Guide.
would be
joinColumn
AddressID
573
.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents