Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Easily configure Hibernate with CFML
The ORM can be configured by a struct of settings set in this.ormSettings
in your main Application.cfc
:
The full list of available properties you can use to configure the ORM are the following:
autoGenMap
true
Specifies whether ColdFusion should automatically generate entity mappings for the persistent CFCs. If autogenmap=false
, the mapping should be provided in the form of .HBMXML
files.
autoManageSession
true
cacheConfig
true
cacheProvider
"ehcache"
Specifies the cache provider that ORM should use as a secondary cache. The values can be:
Ehcache
ConcurrentHashMap
The fully qualified name of the class for any other cache provider.
catalog
Specifies the default Database Catalog that ORM should use.
cfclocation
empty
Specifies the directory (or array of directories) that should be used to search for persistent CFCs to generate the mapping.
Always specify it or pay a performance startup price.
Important:
If it is not set, the extension looks at the application directory, its sub-directories, and its mapped directories to search for persistent CFCs.
datasource
application.datasource
This setting defines the data source to be utilized by the ORM. If not used, defaults to the this.datasource
in the Application.cfc
dbcreate
none
update
: Creates the database according to your ORM model. It only does incremental updates. It will never remove tables, indexes, etc.
dropcreate
: Same as above but it destroys the database if it has ny content and recreates it every time the ORM is reloaded.
none
: Does not change the database at all.
dialect
autodiscover
eventHandling
false
If true, then it enables the ORM event callbacks in entities and globally via the eventHandler
eventHandler
The CFC path of the CFC that will manage the global ORM events.
flushAtRequestEnd
true
Specifies if an orm flush should be called automatically at the end of a request. In our opinion this SHOULD never be true. A database persistence should be done via transaction
tags and good transaction demarcation.
logSQL
false
Specifies if the SQL queries should be logged to the console.
namingstrategy
default
ormconfig
savemapping
false
If enabled, the ORM will create the Hibernate mapping XML (*.hbmxml
) files alongside the entities. This is great for debugging your entities and relationships.
schema
The default database schema to use
secondaryCacheEnabled
false
skipCFCWithError
false
If true
, then the ORM will ignore CFCs that have compile time errors in them. Use false
to throw exceptions.
sqlScript
Path to a SQL script file that will be executed after the ORM is initialized. A great way to seed a database.
useDBForMapping
true
Specifies whether the database has to be inspected to identify the missing information required to generate the Hibernate mapping.
The database is inspected to get the column data type, primary key and foreign key information.
By using the ormsettings.dialect
you can tell Hibernate which specific database dialect to use for building queries. By default, Hibernate tries to inspect the datasource and define it for you. 95% of the time, this works. However, if you want a specific one, then you can use the following names or a fully qualified Java class name.
Cache71
Support for the Caché database, version 2007.1.
CockroachDB192
Support for the CockroachDB database version 19.2.
CockroachDB201
Support for the CockroachDB database version 20.1.
CUBRID
Support for the CUBRID database, version 8.3. May work with later versions.
DB2
Support for the DB2 database, version 8.2.
DB297
Support for the DB2 database, version 9.7.
DB2390
Support for DB2 Universal Database for OS/390, also known as DB2/390.
DB2400
Support for DB2 Universal Database for iSeries, also known as DB2/400.
DB2400V7R3
Support for DB2 Universal Database for i, also known as DB2/400, version 7.3
DerbyTenFive
Support for the Derby database, version 10.5
DerbyTenSix
Support for the Derby database, version 10.6
DerbyTenSeven
Support for the Derby database, version 10.7
Firebird
Support for the Firebird database
FrontBase
Support for the Frontbase database
H2
Support for the H2 database
HANACloudColumnStore
Support for the SAP HANA Cloud database column store.
HANAColumnStore
Support for the SAP HANA database column store, version 2.x. This is the recommended dialect for the SAP HANA database. May work with SAP HANA, version 1.x
HANARowStore
Support for the SAP HANA database row store, version 2.x. May work with SAP HANA, version 1.x
HSQL
Support for the HSQL (HyperSQL) database
Informix
Support for the Informix database
Ingres
Support for the Ingres database, version 9.2
Ingres9
Support for the Ingres database, version 9.3. May work with newer versions
Ingres10
Support for the Ingres database, version 10. May work with newer versions
Interbase
Support for the Interbase database.
JDataStore
Support for the JDataStore database
McKoi
Support for the McKoi database
Mimer
Support for the Mimer database, version 9.2.1. May work with newer versions
MySQL5
Support for the MySQL database, version 5.x
MySQL5InnoDB
Support for the MySQL database, version 5.x preferring the InnoDB storage engine when exporting tables.
MySQL57InnoDB
Support for the MySQL database, version 5.7 preferring the InnoDB storage engine when exporting tables. May work with newer versions
MariaDB
Support for the MariaDB database. May work with newer versions
MariaDB53
Support for the MariaDB database, version 5.3 and newer.
Oracle8i
Support for the Oracle database, version 8i
Oracle9i
Support for the Oracle database, version 9i
Oracle10g
Support for the Oracle database, version 10g
Pointbase
Support for the Pointbase database
PostgresPlus
Support for the Postgres Plus database
PostgreSQL81
Support for the PostgrSQL database, version 8.1
PostgreSQL82
Support for the PostgreSQL database, version 8.2
PostgreSQL9
Support for the PostgreSQL database, version 9. May work with later versions.
Progress
Support for the Progress database, version 9.1C. May work with newer versions.
SAPDB
Support for the SAPDB/MAXDB database.
SQLServer
Support for the SQL Server 2000 database
SQLServer2005
Support for the SQL Server 2005 database
SQLServer2008
Support for the SQL Server 2008 database
Sybase11
Support for the Sybase database, up to version 11.9.2
SybaseAnywhere
Support for the Sybase Anywhere database
SybaseASE15
Support for the Sybase Adaptive Server Enterprise database, version 15
SybaseASE157
Support for the Sybase Adaptive Server Enterprise database, version 15.7. May work with newer versions.
Teradata
Support for the Teradata database
TimesTen
Support for the TimesTen database, version 5.1. May work with newer versions
Here is an example configuration from the popular ContentBox Modular CMS application
You can define your own naming convention for table and column names by pointing this.ormSettings.namingStrategy
to a custom CFC path:
The UnderscoreNamingStrategy.cfc
component should then define two methods: getTableName()
and getColumnName()
:
Allows the engine to manage the Hibernate session. It is recommended not to let the engine manage it for you.
Use transaction
blocks in order to demarcate your regions that should start, flush and end a transaction.
Specifies the location of the configuration file that the secondary cache provider should use. This setting is used only when secondaryCacheEnabled=true
. See below.
See below.
The dialect to use for your database. By default Hibernate will introspect the datasource and try to figure it out. See the dialects section below. You can also use the fully Java qualified name of the class. See the section below.
Defines the naming convention to use on table and column names.
- default
: Uses the table or column names as is
- smart
: This strategy changes the logical table or column name to uppercase.
- CFC PATH
: Use your own CFC to determine naming - see .
The path to a custom Hibernate configuration file: - hibernate.properties - hibernate.cfc.xml Please see
Enable the secondary cache or not. See our section.
Release history for all versions of the Ortus ORM Extension
In this section, you will find the release notes for each version we release under this major version. If you are looking for the release notes of previous major versions, use the version switcher at the top left of this documentation book. Here is a breakdown of our major version releases.
A new layout, cache and logging improvements, and much more.
Our initial fork of the Lucee Extension.
Get up and running in seconds!
You can install this extension by adding the extension ID to the lucee-extensions
environment variable and restarting the server:
You can install a specific version by appending a version string to the extension ID:
(For all available version numbers, see our Release History or the GitHub Releases page.)
Running the box server set env.lucee-extensions
command will edit your server.json
file to look something like this:
This config instructs Lucee (not CommandBox) to install the Ortus ORM Extension when Lucee starts up.
You can manually install the extension by opening the Lucee server admin page and browsing to Extension > Applications
page, where you'll see a "Ortus ORM Extension" option. Clicking this option will open the installation screen, where you can choose any extension version and click "Install" to install from Forgebox.
You can also download a .lex
file from our downloads page and upload this through the Lucee Server admin's Applications page.
Whichever method you use to install the extension, we recommend restarting the server after installing.
Via CommandBox:
The Ortus ORM Extension is a native Lucee Extension that allows your CFML application to integrate with the powerful Hibernate ORM
The Ortus ORM Extension is a native Lucee Extension that allows your CFML application to integrate with the powerful Hibernate ORM. With Hibernate, you can interact with your database records in an object oriented fashion, using components to denote each record and simple getters and setters for each field value:
The Ortus ORM extension also enables transactional persistence, where an error during a save will roll back the entire transaction to prevent leaving the database in a broken state:
Lucee 5.3.9.73 and above
Java 8, 11 or 17
The Ortus ORM Extension bundles Hibernate 5.6.15.FINAL
since extension version 6.2.0.
Previous versions of the Ortus ORM Extension bundle Hibernate 5.4.29.FINAL
:
The Ortus ORM extension is an open source Lucee server extension with no license purchase necessary. If you are looking to further the development of this extension, consider sponsoring a feature or opening a support contract.
Add Object Relational Mapping to any CFML app with Hibernate ORM
Use native CFML methods to update and persist entities to the database (entityNew()
, entitySave()
, ormFlush()
, etc.)
Supports 80+ database dialects, from SQLServer2005
to MySQL8
and PostgreSQL
60% faster startup than the Lucee Hibernate extension
Generate your mapping XML once and never again with the autoGenMap=false
ORM configuration setting
React to entity changes with pre and post event listeners such as onPreInsert()
, onPreUpdate()
and onPreDelete()
Over 20 native CFML functions:
EntityDelete()
EntityLoad()
EntityLoadByExample()
EntityLoadByPK()
EntityMerge()
EntityNameArray()
EntityNameList()
EntityNew()
EntityReload()
EntitySave()
EntityToQuery()
ORMClearSession()
ORMCloseAllSessions()
ORMEvictCollection()
ORMEvictEntity()
ORMEvictQueries()
ORMExecuteQuery()
ORMFlush()
ORMGetSession()
ORMGetSessionFactory()
ORMReload()
See the extension changelog for a full list of enhancements and bug fixes.
Our expertise with Hibernate ORM and Lucee Server allows us to give back to the community, as well as offer premium support to enterprises looking for a level up in their Hibernate implementations. If you need performance optimization, session management or caching integrations, please contact us for support.
Support Plans: https://www.ortussolutions.com/services/support
Bug Tracker: https://ortussolutions.atlassian.net/browse/OOE
More info on this documentation gitbook for the Ortus ORM Extension
The source code for this book is hosted in GitHub:
The majority of code examples in this book are done in cfscript
.
Both Lucee Server and Hibernate ORM are licensed under the LGPL v2.1.
The information in this book is distributed “as is”, without warranty. The author and Ortus Solutions, Corp shall not have any liability to any person or entity with respect to loss or damage caused or alleged to be caused directly or indirectly by the content of this training book, software and resources described in it.
Shalom Children’s Home is one of the ministries that is dear to our hearts located in El Salvador. During the 12 year civil war that ended in 1990, many children were left orphaned or abandoned by parents who fled El Salvador. The Benners saw the need to help these children and received 13 children in 1982. Little by little, more children came on their own, churches and the government brought children to them for care, and the Shalom Children’s Home was founded.
Shalom now cares for over 80 children in El Salvador, from newborns to 18 years old. They receive shelter, clothing, food, medical care, education and life skills training in a Christian environment. The home is supported by a child sponsorship program.
We have personally supported Shalom for over 6 years now; it is a place of blessing for many children in El Salvador that either have no families or have been abandoned. This is good earth to seed and plant.
Version 5.x release notes for the Ortus ORM Extension
We now set the JAXB system property based on the JRE version. If less than JRE 11, we set . If JRE 11 or greater, we set .
This prevents the following warning from being logged on each ORM method call:
Improved logo for Lucee admin 🤩
Switched to Maven for a faster, more stable build process
ORMExecuteQuery ignores argument if struct is passed
Dramatic improvements in initialization performance
Cuts ORM reload time by 60%
Better build/test documentation
Improved maintenance and build docs
How do Hibernate logs work in the Ortus ORM Extension?
The Ortus ORM Extension reconfigures all Hibernate logging output on startup to log ERROR
-level events to the server console.
This depends on the version of Lucee you are running - specifically, on whether you're on Log4J 2 or not.
Lucee versions containing the older log4j 1.x can use this code to set a custom logging level and redirect the Hibernate logs to the server console:
All about entity identifiers, from primary keys, and generators to composite keys and field types.
Identifier properties are denoted via fieldtype="id"
.
We highly recommend disabling updates on identifier properties via update="false"
:
The Assigned generator is the default identifier generator type, and simply allows the application (your CFML) to assign identifier values prior to insertion. You can think of this as generator=none
.
A select generator will attempt to select the next identifier value from the specified selectKey
column:
The UUID generator uses Hibernate's uuid generator under the hood:
The Increment generator uses a simple incrementing value to create identifiers. Do not use in concurrent applications, as the values may no longer be unique.
There are several lesser-known identifier generator types, including:
foreign
- use a foreign CFC's generator configuration
seqhilo
sequence
select
- select the next value from the column denoted in selectKey
uuid
- use Hibernate's UUID generation
Entity properties are how we map table columns to CFML object values. You can specify an entity property by setting persistent="true"
on any property
inside a persistent CFML component:
By default, all properties inside a persistent=true
component are assumed to be persistent as well. Thus, we can skip the persistent=true
annotation for brevity:
Make sure you quote datetime dbdefault
values to avoid invalid date errors in MySQL:
There are several "type" concepts and annotations you may need to use to keep the proper format when persisting or retrieving table data. While these may look similar, they are not equivalent.
The fieldtype
attribute allows you to define the behavior and purpose of this property:
There are several options for the fieldtype
value:
column
- By far the most common, this is the default behavior of every field.
id
- Notes this field as the primary key or part of the a composite key.
collection
- Denote a collection of items - this could represent a struct, an array
timestamp
- Denote a timestamp field
primary
- Not currently used.
These property annotations are used when setting fieldtype="collection"
and collectiontype
is either struct
or map
.
You can freely contribute to it and submit pull requests. The contents of this book is copyright by and cannot be altered or reproduced without author's consent. All content is provided "As-Is" and can be freely distributed.
The majority of code generation and running of examples are done via CommandBox: The ColdFusion (CFML) CLI, Package Manager, REPL -
We highly encourage contribution to this book and our open source software. The source code for this book can be found in our where you can submit pull requests.
10% of the proceeds of this book will go to charity to support orphaned kids in El Salvador - . So please donate and purchase the printed version of this book, every book sold can help a child for almost 2 months.
See .
We now set a System property to ensure the JAXB API can find its implementation in CommandBox environments. This may trigger a log message, but shouldn't cause any concern. Vanilla Tomcat installations may need to overwrite or clear this property.
Entity changes made in and do not persist
Improved entity event listeners for a much speedier ORM startup ()
New and Improved logo for Lucee admin visibility ()
Entity has no state when listener method (, for example) is fired (, )
Upgraded dom4j library from 1.6.1 to 2.1.4. This removes in dom4j's XML parsing capabilities.
Adds support for -
Adds javadocs auto-published to
ORM events not firing ()
Session close on transaction end ()
length not used on varchar fields ()
For versions of Lucee running log4j 2.x, the above workaround does not apply. If you are interested in tweaking the Hibernate logging level in the Lucee Hibernate extension, I would suggest and future users can benefit from the shared knowledge.
lets the application assign an identifier to the object before save() is called. This is the default strategy if no element is specified. -
Assigned generators will commonly use to assign the identifer value:
retrieves a primary key, assigned by a database trigger, by selecting the row by some unique key and retrieving the primary key value. -
uses a 128-bit UUID algorithm to generate identifiers of type string that are unique within a network (the IP address is used). The UUID is encoded as a string of 32 hexadecimal digits in length. -
Generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. Do not use in a cluster. -
version
- Denote a version field, useful for on an entity
one-to-one
- Denote a
one-to-many
- Denote a
many-to-one
- Denote a
many-to-many
- Denote a
Looking for better support of a specific persistent attribute? .
persistent
boolean
Define this property as a persistent property. If false
, this property will be completely ignored in Hibernate / the ORM extension.
name
string
Property name
default
string
Default value for the property. This only reaches the CFML engine, and does not affect creation of the entity table.
column
string
Table column where the property value is stored.
dbDefault
string
Set the default value for the property.
type
date
,numeric
CFML data type
fieldtype
column
,id
, one-to-many
Denote a special type of field, like an identifier or relationship field.
ormType
big_decimal
,timestamp
Data type for the database value.
sqlType
nvarchar
A vendor-specific SQL type used for table creation only. This can normally be ignored.
generator
string
One of increment
,identity
,native
,seqhilo
,uuid
,guid
,select
,foreign
, assigned
params
struct
, string
{ "table: "uuid_table", column: "uuid_value_column" }
sequence
string
selectkey
string
Only used with generator=select
. Specify the select key to use when selecting sequence values from the database.
generated
string
always
, insert
, never
.
insert
boolean
Allow inserting values to new rows.
update
boolean
Allow value updates on existing rows.
notnull
boolean
Specify a not-null constraint.
uniquekey
string
Specify a key name for a unique constraint. Useful for defining a unique constraint across multiple columns.
unique
boolean
Specify a unique constraint. Default false
.
validateParams
string
Not currently supported
validate
string
Not currently supported
structkeycolumn
string
structkeytype
string
elementtype
string
elementcolumn
string
table
string
Define the table where the foreign items are stored.
lazy
boolean
, string
Define a lazy association retrieval type. One of true
, false
, extra
.
inverse
boolean
Specify that the association "owner" is referenced and managed on the opposite entity - not this current entity.
inversejoincolumn
string
Specify the join column on the associated entity. For inverse
associations only.
linkschema
string
Specify the schema name of the link table
linkcatalog
string
Specify the catalog name of the link table
linktable
string
Specify the name of the link table
missingRowIgnored
boolean
Do not throw an error if a foreign key has no match in the foreign entity
fkcolumn
string
orderby
string
fetch
string
cascade
string
constrained
boolean
Only valid for one-to-one
relationships. See Hibernate 3.3 Mapping Documentation
optimisticLock
boolean
Enable optimistic locking on this association. One of all
, dirty
, version
, none
.
mappedby
string
Specify the property on the association that maps to this entity.
cfc
string
Specify the CFC location of the foreign entity.
joinColumn
string
Join the foreign entity on this column in this entity.
where
string
Arbitrary SQL where clause for the relation.
singularname
Not currently supported
scale
integer
length
integer
precision
integer
formula
string
Define this property as a computed property by using a SQL query to determine the property value. Formula properties cannot be modified.
index
string
Key name for a property value index.
cacheUse
string
Define a cache type to use for this property. One of read-only
, nonstrict-read-write
, read-write
, or transactional
.
cacheName
string
Set the name of the cache to use for this property.
unSavedValue
string
Set a value to use for newly instantiated objects.
For full Hibernate configuration support, you can point the ORM extension to an XML file containing any configuration properties you wish to configure:
You can then populate the XML file with valid Hibernate configuration syntax:
Hibernate's secondary cache is a powerful tool that can greatly improve the performance of your application. By storing frequently accessed data in memory, the secondary cache can reduce the number of database queries that need to be made, resulting in faster response times and more efficient use of system resources. Whether you're working on a small project or a large enterprise application, the secondary cache is an essential part of any Hibernate-based system. So if you want to get the most out of your Hibernate application, take advantage of this powerful caching feature!
Please see the caching section for all the wonderful caching strategies you can do with Hibernate.
A secondary cache provider is a class that manages a level of caching secondary to Hibernate's main caching context - the Hibernate session. A secondary cache enables longer-running cache contexts, more fine-grained control over cache busting, and other performance-related benefits.
The only setting necessary to enable secondary caching is the secondaryCacheEnabled
setting:
To configure the caching, specify the path to an XML cache configuration file in cacheConfig
:
This ehcache.xml
cache configuration then should look something like this:
While there is a cacheProvider
setting, only EHCache (currently) is supported as a secondary cache provider.
Thus, any usage of cacheProvider
other than "ehcache"
will be ignored.
Savepoints are not currently supported on ORM transactions.
The Ortus ORM Extension offers a number of CFML functions for loading and manipulating entities as well as managing the ORM session:
EntityDelete
allows you to delete the row associated with an instantiated entity from the database:
Only a single argument is accepted - the entity to delete - and the deletion is not persisted until the session is flushed.
Returns: null
Returns: Array
|Component
|null
Returns: Array
|Component
|null
EntityLoadByPK()
allows you to instantiate an entity using the row identified by a primary key:
A third argument, unique
, is documented but not implemented in either the Lucee Hibernate extension or the Ortus ORM Extension.
Returns: Component
|null
EntityMerge()
will merge a "detached" entity (meaning, not connected to any open session) back into the session.
For example, running ormClearSession()
will detach all loaded entities from the session. If you then make changes to an entity via a setter and run ormFlush()
, those entity modifications will not be persisted unless you first merge the entity back to the session:
Returns: Component
EntityNameArray()
returns an array of all mapped entity names for the CFML application:
EntityNameArray accepts no arguments.
Returns: Array
True to its name, EntityNameList returns a string list of all mapped entity names for the CFML application:
You can pass a string delimiter value as the first argument, if you don't like commas:
Returns: string
The entityNew()
method allows you to create a new instance of a known entity type:
You can also pass a struct of properties to populate into the entity:
Note that if you try to populate a property which does not exist, you will get an error:
This will throw an error: component [Auto] has no function with name [setPROPTHATDOESNTEXIST]
Returns: Component
entityReload()
will reload or refresh the entity state from the database. Local, unpersisted modifications will be replaced with database values.
Here's a quick example:
Returns: null
EntitySave()
is how you save entity modifications. The changes will not persist to the database until ormFlush()
is called:
EntitySave accepts an optional boolean parameter, forceInsert
, which will tell Hibernate to skip the entity existence check and insert the entity:
Most of the time this will be unnecessary.
Returns: null
Returns: Query
Returns: Boolean
Returns: null
Returns: null
Returns: null
Returns: null
Returns: null
Returns: null
Returns: Array
|Struct
|any
Returns: null
Returns: Session
Returns: SessionFactory
Alias for ORMExecuteQuery()
.
Added in v6.4.0
(unreleased, version number subject to change.) - 5600833
Returns: Array
|Struct
|any
Returns: null
Learn the basics of modeling ORM entities
A persistent entity is a CFML component that is marked as a database entity via the persistent
annotation upon the component definition:
By default, the entity name will be the CFC file name - minus the file extension, of course. We can modify the entity name via the entityname
annotation:
And the table name via the table
annotation:
Here's the full list of available annotations for a persistent component:
This page is missing documentation - would you care to ?
persistent
boolean
false
Mark this component as an ORM entity
entityname
string
Set a custom entity name which is different than the CFC name
table
string
Specify the database table name
schema
string
Specify the database schema name.
catalog
string
Specify the database catalog name.
dynamicinsert
Specifies whether INSERT SQL is to be generated at runtime. Only those columns whose values are not null are included in the SQL.
dynamicinsert
boolean
false
Specifies whether INSERT SQL is to be generated at runtime. Only those columns whose values are not null are included in the SQL.
dynamicupdate
boolean
false
Specifies whether UPDATE SQL is to be generated at runtime. Only those columns whose values are not null are included in the SQL.
readonly
boolean
false
Specify whether table is readonly or not
selectbeforeupdate
boolean
Specify whether Hibernate should never perform an SQL UPDATE unless it is certain that an object is actually modified. In cases when a transient object is associated with a new session using update(), Hibernate performs an extra SQL SELECT to determine if an UPDATE is actually required.
optimisticlock
string
Determines the locking strategy. It can be any one of: all
,dirty
,version
,none
batchsize
integer
An integer value that specifies the number of records to be retrieved at a single instance.
lazy
boolean
true
Whether loading is to be done lazily or not.
rowid
string
Specify the row id
discriminatorColumn
string
Use this attribute to define the discriminator column to be used in inheritance mapping
discriminatorValue
string
Use this attribute to define the discriminator value to be used in inheritance mapping
joinColumn
string
Define a join column for inheritance mapping
embedded
boolean
Marks CFC as embedded, used when a CFC has an embedded object which also needs to be persisted along with the parent's data
cacheUse
string
Specify the caching strategy to be used for caching this component's data in the secondary cache: read-only
cacheName
string
Specify the name of the secondary cache
saveMapping
boolean
false
Specifies whether the generated Hibernate mapping file has to be saved to disk. If you set the value to true, the Hibernate mapping XML file is saved as {CFC name}.hbm.xml
in the same directory as the CFC.
datasource
string
Name a specific datasource to persist this entity to.
Easily run actions on entity insertion, update, and more with event listeners
Hibernate ORM allows reacting to various events in the session lifecycle such as onPreInsert
, onPostUpdate
, onFlush
, etc. You can enable event handling in CFML by setting eventHandling
to true
in your this.ormSettings
struct:
This will enable two different event listener types for listening to Hibernate events:
Listen to all events across all entities via the global event handler
Listen to specific events on a specific entity via entity event handler methods
To use a global event handler, you must set a path to the global event handler using the eventHandler
setting:
The EventHandler.cfc
must then contain function definitions matching the ORM events you wish to listen for.
Currently, the available event names are:
onFlush
preLoad
postLoad
preInsert
postInsert
preUpdate
postUpdate
preDelete
onDelete
postDelete
onEvict
onClear
onDirtyCheck
onAutoFlush
Here's an example of an EventHandler configured for all events:
You can also listen to events on a specific entity at the entity level by adding methods to the entity (component) itself:
Here is the full list of event types which can be listened to in entity event listeners:
preLoad
postLoad
preInsert
postInsert
preUpdate
postUpdate
preDelete
onDelete
postDelete
Learn transaction management with the ORM Extension
A transaction is any discrete unit of work used to pool database queries and statements to execute at once. This helps us to prevent a failed update from leaving the database in a broken state.
To denote a transaction, we wrap it in the transaction{}
tag:
The transaction will automatically commit (persist) at the end of the transaction block.
Savepoints are not currently supported on ORM transactions.
This section is missing documentation - would you care to ?
This section is missing documentation - would you care to ?
Looking for ORM savepoint support? .
Entity relationships let you define an association between two entity types.
Every relationship property must define the state of the relationship. In each case, the relationship property is defined in an entity which represents the "left" side of the relationship. If you bring a Posts
relationship into the User
entity, then from the User
entity, the User
is the left side of the relationship, and Posts
is the right.
A one to one relationship couples a single row on the left side to a single row on the right side:
One to one relationships can be seen as simply extending the entity with additional information. Since there is no possibility of multiple records per entity instance, it may be worthwhile to set lazy=false
to fetch the related entity along with any entity load:
A one to many relationship couples a single row on the left side (the "one") to multiple rows on the right side (the "many"):
You'll normally want to set lazy="true"
to (for example) avoid fetching every Post on a User:
A many to one relationship couples multiple rows on the left side (the "many") to a single row on the right side( the "one"):
Thus, a single Post can have only one Author... but an author (or a User, really) can have many Posts.
A many to many relationship allows each entity to relate to multiple rows on the opposite side. A good example might be a blog which allows multiple authors for a single blog post. Each blog post can then have multiple authors, and each author has (likely) written multiple blog posts:
The linktable
attribute is required on a many-to-many
property to set the locationfor storing join records. You can further alter the storage location via linkschema
and linkcatalog
:
On many* relationships like one-to-many
, many-to-one
, etc., you'll be manipulating the full set of items via the property name: hasAuthors()
, setAuthors()
, etc. However, this plural terminology becomes weird when used on a single item addition or removal, such as addAuthors( Author )
. For this reason, you can define a singularName=STRING
attribute to clean up your entity manipulation:
Man, you wanna get lazy? How about don't-fetch-the-data-until-you-need-it kinda lazy?
Using lazy=true
, we can tell Hibernate not to fetch the relational data unless and until a method call such as Authors()
attempts to load it. This greatly improves performance on page requests which do not need that particular data:
We can also use lazy=extra
to only retrieve the rows that we touch. This may work well if we commonly only access a few rows out of the full set of child items:
This section is missing documentation - would you care to ?
Version 6.x release notes for the Ortus ORM Extension
Fixes empty string values coercing to NULL
when no property type is declared. - Resolves OOE-25, introduced in 6.5.0.
Fixes an incorrect property name lookup for the unsavedValue
persistent property attribute.
Fixes the pre-event listeners to ignore empty strings in entity state properties if the field type is one of string
, character
, or text
. This resolves issues where a preInsert()
or preUpdate()
throws a "can't cast [] to date value" when processing event listeners if a date field (for example) is unpopulated or has an empty default
attribute.
Add the entity name to the exception message when attempting to persist changes from preInsert
or preUpdate
event listeners. The updated exception message is now:
Error populating event state for persistance in [<entity name>] entity pre-event listener method: <error message from Hibernate>
Bump Lucee build dependency to 5.4.4.38
to avoid vulnerable dependencies in the build process.
Resolve an Uncontrolled Resource Consumption vulnerability disclosed on 12/4/2023 by upgrading logback-core
to 1.3.14
. See vulnerability details.
New ORMQueryExecute()
alias for the ORMExecuteQuery
. This new alias behaves identically to the ORMExecuteQuery()
method, but is named consistently with the queryExecute()
method.
Fixes custom configuration support via this.ormSettings.ormConfig
.
Fixes named argument support for entityLoad()
- LDEV-4285
Fixes named argument support for entityLoadByPK()
- LDEV-4461
While not technically a change in ORM functionality, the useDBforMapping
implementation has been greatly improved "under the hood", with tests to boot.
Fixed pre-event listeners to include parent component properties when checking for entity mutations to persist back to the event entity state. This resolves issues with changes made in preInsert()
/preUpdate()
not persisting if the changes are made on a persistent property from a parent component. Resolves OOE-14.
Refactored nullability checks to occur after pre-event listener methods fire. Resolves OOE-12
Added context to the error message in CFCGetter
, which handles retrieving entity values from Hibernate code. This improves odd error messages in some edge cases with the Hibernate tuplizer.
Switched the EHCache library to use net.sf.ehcache.internal:ehcache-core.
Upgrades EHCache version from 2.10.6
to 2.10.9.2
.
Drops an embedded rest-management-private-classpath
directory
Drops a number of (unused) vulnerable jackson and jetty libraries such as jackson-core.
As an added bonus, this reduces the final .lex
extension file size by over 6 MB. 🎉
Note: While it is not 100% clear, some of these CVEs may have been false positives.
This brings the Hibernate dependencies up to date (released Feb. 2023), and should not change any CFML-facing features for most users. (See CLOB columns in Postgres81)
See the migration guides for more info:
Due to the Hibernate 5.6 upgrade, if you are using the PostgreSQL81
dialect and have CLOB
columns in your database, it is recommended you migrate existing text columns for LOBs to oid
.
The default ehcache.xml
for EHCache changed to include clearOnFlush="true"
and diskSpoolBufferSizeMB="30MB"
properties to match Adobe ColdFusion 9's default ehCache.xml
config. Both these values represent default settings in EHCache itself.
Fixes handling of "timezone"
-typed column values. Previously, fields defined with ormtype="timezone"
would neither use the default
value nor allow new values to be set. OOE-10
Fixes entity state changes in preInsert()
/preUpdate()
listeners for properties with no default
defined. OOE-9
Lots of java source code cleanup that won't affect the CFML experience, but will aid in faster development and fewer bugs.
Any hibernate exceptions returned during schema generation are once again logged to the Lucee ORM log file.
Dropped the public method from the Dialect class. This method was unused (to my knowledge) and unnecessary.
Switched to Snyk vulnerability scanner to limit false positives. Security vulnerabilities will now be published on the GitHub repository's Security Advisories page.
Bumped Lucee dependency to to remove vulnerability notices on org.apache.tika:tika-core and commons-net:commons-net. These vulnerabilities are only theoretical, since Lucee is a dependency and not bundled with the extension.
Second-Level Caching
The extension will now throw an error if you try to configure an unsupported cache provider like , , etc. Previously, the extension would silently switch to ehcache if any cache provider besides EHCache was configured.
Hibernate Logging
This version re-enables Hibernate logging via SLF4j and LogBack. Hibernate root and cache loggers are defaulted to level, while SQL logging is set to if is enabled. (Set to .)
OWASP Dependency CVE Scans
The extension GitHub Release page now generates a dependency CVE report via Jeremy Long's OWASP dependency-check maven plugin. Any known CVEs contained in dependencies ( excluding and -scoped dependencies) will be noted in each release's CVE report artifact.
New Repo Layout
Java source moved to
All java classes are now under the package
Dropped the java source format-on-push in favor of format-on-save IDE tooling
New Test Layout
Internal tests rewritten to native Testbox specs
Cloned all ORM tests from the Lucee repository
Updated to TestBox 5.0
New Build (and .jar file) Layout
We re-architected the build to inline most dependencies. I.e. we no longer copy in extension dependencies as (custom-built) OSGI bundles, but instead as compiled classes.
This resolves intermittent issues with bundle resolution and/or duplicate bundle collision upon installing the ORM extension into a Lucee server prior to uninstalling the Lucee Hibernate extension.
This also removes a number of direct dependencies on custom OSGI bundles, thus it is more reliable and will offer easier dependency upgrades with less pain.
Other
The attribute is deprecated in Hibernate 5.x, and is no longer generated on HBM/XML mapping files to avoid Hibernate warning that Use of DOM4J entity-mode is considered deprecated.
The definition file for all built-ins was missed during the conversion to a Maven build. (Since v5.4.29.25). This caused the and built-in method calls to be picked up by Lucee core before being routed to this extension. No known errors resulted from this mistake, but we feel embarrassed anyway. 😅
Clear ORM context data once per ORM reload, not once per ORM entity parsing. This should improve ORM startup/reload time and avoid difficult session or cache manager lifecycle issues.
Improve your database performance with secondary caching in Hibernate ORM.
A secondary cache provider is a class which manages a level of caching that is secondary to Hibernate's main caching context - the Hibernate session. A secondary cache enables longer-running cache contexts, more fine-grained control over cache busting, and other performance-related benefits.
The only setting necessary to enable secondary caching is the secondaryCacheEnabled
setting:
To configure the caching, specify the path to an XML cache configuration file in cacheConfig
:
This ehcache.xml
cache configuration then should look something like this:
Notice how our ehcache.xml
defines a default cache configuration?
We highly recommend adding a cache configuration for each cacheable entity. This will help you optimize caching, and will silence error logs like the below:
Here's a quick example. Say we have an Autos.cfc
persistent component with caching enabled:
For this entity, we'll want to create a <cache></cache>
entry with a name
attribute that matches the entity name OR our cacheName
component annotation:
While there is a cacheProvider
setting, only EHCache (currently) is supported as a secondary cache provider.
Thus, any usage of cacheProvider
other than "ehcache"
will be ignored.