Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
property name="id"
fieldtype="id"
ormtype="string"
generator="assigned"
update="false";property name="id"
fieldtype="id"
generator="assigned"
update="false";function preInsert( entity ){
setId( createUUID() );
}property name="userID"
fieldtype="id"
generator="select"
selectKey="ssn"
update="false";property name="userID"
fieldtype="id"
generator="uuid"
update="false";property name="userID"
fieldtype="id"
generator="increment"
update="false";this.ormSettings = {
// ...
ormconfig : "./config/persistence.xml"
};<!-- persistence.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"https://hibernate.org/dtd/hibernate-reverse-engineering-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- https://docs.jboss.org/hibernate/orm/5.4/javadocs/org/hibernate/cfg/AvailableSettings.html#USE_SQL_COMMENTS -->
<property name="hibernate.use_sql_comments">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
</session-factory>
</hibernate-configuration>Version 5.x release notes for the Ortus ORM Extension
component entityName="Auto" persistent="true" {
property name="id" type="string" fieldtype="id" ormtype="string";
property name="make" type="string";
property name="model" type="string";
function onPreInsert(){
log.info( "Inserting new Auto: #getMake()# #getModel()#" );
}
}transaction{
// queries go here
}SQLServer2005 to MySQL8 and PostgreSQL
WARNING: Using non-standard property: javax.xml.bind.context.factory. Property javax.xml.bind.JAXBContextFactory should be used instead.transaction{
try{
entitySave(
entityNew( "Purchase", {
productID : "123-expensive-watch",
purchaseTime : now(),
customerID : customer.getId()
})
);
var cartProducts = entityLoad( "CartProduct", customer.getID() );
entityDelete( cartProducts );
} catch ( any e ){
// don't clear the user's cart if the purchase failed
transactionRollback();
rethrow;
}
}box server set env.LUCEE_EXTENSIONS="D062D72F-F8A2-46F0-8CBC91325B2F067B" && box restartbox server set env.LUCEE_EXTENSIONS="D062D72F-F8A2-46F0-8CBC91325B2F067B;version=6.5.2" && box restartcacheConfig:{
// ...
"env":{
"LUCEE_EXTENSIONS":"D062D72F-F8A2-46F0-8CBC91325B2F067B;version=6.5.2"
}
}server restartthis.ormSettings = {
secondaryCacheEnabled : true
};this.ormSettings = {
secondaryCacheEnabled: true,
cacheConfig : "./config/ehcache.xml"
};<?xml version="1.0" encoding="UTF-8"?>
<ehcache
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" name="default">
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120"
maxElementsOnDisk="10000000" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<persistence strategy="localTempSwap"/>
</defaultCache>
<cache
name="Autos"
maxElementsInMemory="20"
overflowToDisk="false"
eternal="true">
</cache>
</ehcache><defaultCache
maxElementsInMemory="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120"
maxElementsOnDisk="10000000" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<persistence strategy="localTempSwap"/>
</defaultCache>WARN: HHH90001006: Missing cache[default-update-timestamps-region] was created on-the-fly. The created cache will use a provider-specific default configuration: make sure you defined one. You can disable this warning by setting 'hibernate.cache.ehcache.missing_cache_strategy' to 'create'component persistent="true" cacheUse="true"{
// persistent properties...
}<cache
name="Autos"
maxElementsInMemory="20"
overflowToDisk="false"
eternal="true">
</cache>this.ormSettings = {
secondaryCacheEnabled : true,
// NOT SUPPORTED!
cacheProvider : "ConcurrentHashMap"
};this.ormSettings = {
eventHandling: true
};this.ormSettings = {
eventHandling: true,
eventHandler : "path/to/global/EventHandler.cfc"
};component {
public component function init(){
return this;
}
function onFlush( entity ) {
// Do something upon function call
}
function preLoad( entity ){
// Do something upon function call
}
function postLoad( entity ){
// Do something upon function call
}
function preInsert( entity ){
// Do something upon function call
}
function postInsert( entity ){
// Do something upon function call
}
function preUpdate( entity, Struct oldData ){
// Do something upon function call
}
function postUpdate( entity ){
// Do something upon function call
}
function preDelete( entity ){
// Do something upon function call
}
function onDelete( entity ) {
// Do something upon function call
}
function postDelete( entity ) {
// Do something upon function call
}
function onEvict() {
// Do something upon function call
}
function onClear( entity ) {
// Do something upon function call
}
function onDirtyCheck( entity ) {
// Do something upon function call
}
function onAutoFlush( entity ) {
// Do something upon function call
}
}component persistent="true"{
function preInsert( entity ){
setDateCreated( now() );
}
function preUpdate( entity ){
setDateModified( now() );
}
}entityDelete( myEntity );entityDelete( myEntity );
// entity (row) still exists in the database.
ormFlush();
// entity (row) is now wiped from the database.var theUser = entityLoadByPk( "User", url.userID );var detachedAutoEntity = entityLoadByPK( "Auto", "12345" );
// make a change but don't save it
detachedAutoEntity.setModel( "Fusion" );
// clear session - will "detach" the entity
ormClearSession();
// "merge" it back to the session
var merged = entityMerge( detachedAutoEntity );
// changes should be reflected in the new entity
expect( merged.getModel() ).toBe( "Fusion" );var entityTypes = entityNameArray();var entityTypes = entityNameList();var entityTypes = entityNameList( "|" );var myCar = entityNew( "Auto" );var myCar = entityNew( "Auto", {
make : "Ford",
model : "Fusion",
id : createUUID()
} );var myCar = entityNew( "Auto", {
make : "Ford",
model : "Fusion",
propThatDoesntExist : "abc"
} );var myCar = entityLoadByPK( "Auto", "12345" );
// make a change but don't save it
myCar.setModel( "Revuelto" );
// reload the entity
entityReload( myCar );
// our local changes should be replaced with the DB value
expect( myCar.getModel() ).toBe( "Aventador" );var myCar = entityNew( "Auto", {
make : "Ford",
model : "Fusion",
id : createUUID()
} );
entitySave( myCar );
ormFlush();var myCar = entityNew( "User", {
username : "Johnny.Appleseed",
password : "McinT0sh"
} );
entitySave( myCar, true );void function setupHibernateLogging( level = "WARN" ){
var Logger = createObject( "java", "org.apache.log4j.Logger" );
var log4jLevel = createObject( "java", "org.apache.log4j.Level" );
var hibernateLog = Logger.getLogger( "org.hibernate" );
// set a custom log level
hibernateLog.setLevel( log4jLevel[ arguments.level ] );
/**
* Redirect all Hibernate logs to system.out
*/
if ( listFindNoCase( "Lucee", server.coldfusion.productname ) ) {
var printWriter = getPageContext().getConfig().getOutWriter();
var layout = createObject( "java", "lucee.commons.io.log.log4j.layout.ClassicLayout" );
var consoleAppender = createObject( "java", "lucee.commons.io.log.log4j.appender.ConsoleAppender" ).init(
printWriter,
layout
);
hibernateLog.addAppender( consoleAppender );
writeDump( var = "** Lucee Hibernate Logging Redirected", output = "console" );
}
}component persistent="true"{
property name="name" type="string" persistent="true";
}component persistent="true"{
property name="name" type="string";
}
this.ormSettings = {
secondaryCacheEnabled : true
};this.ormSettings = {
secondaryCacheEnabled: true,
cacheConfig : "./config/ehcache.xml"
};<?xml version="1.0" encoding="UTF-8"?>
<ehcache
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" name="default">
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120"
maxElementsOnDisk="10000000" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<persistence strategy="localTempSwap"/>
</defaultCache>
<cache
name="Autos"
maxElementsInMemory="20"
overflowToDisk="false"
eternal="true">
</cache>
</ehcache>this.ormSettings = {
secondaryCacheEnabled : true,
// NOT SUPPORTED!
cacheProvider : "ConcurrentHashMap"
};property
name ="createdOn"
ormtype ="datetime"
dbdefault="'2016-10-10'";property
name="userID"
fieldtype="id"
type="string";property name="totalPosts"
ormType="integer"
formula="(
SELECT COUNT(*)
FROM posts
WHERE posts.FK_user = id
)";component{
this.ORMenabled = true;
this.ormSettings = {
// << Here Be ORM Configuration! 🤪 >>
};
}// THE CONTENTBOX DATASOURCE NAME
this.datasource = "contentbox";
// ORM SETTINGS
this.ormEnabled = true;
// cfformat-ignore-start
this.ormSettings = {
// ENTITY LOCATIONS, ADD MORE LOCATIONS AS YOU SEE FIT
cfclocation : [
// If you create your own app entities
"models",
// The ContentBox Core Entities
"modules/contentbox/models",
// Custom Module Entities
"modules_app",
// Custom Module User Entities
"modules/contentbox/modules_user"
],
// THE DIALECT OF YOUR DATABASE OR LET HIBERNATE FIGURE IT OUT, UP TO YOU TO CONFIGURE.
dialect : request.$systemHelper.getSystemSetting( "ORM_DIALECT", "" ),
// DO NOT REMOVE THE FOLLOWING LINE OR AUTO-UPDATES MIGHT FAIL.
dbcreate : "update",
secondarycacheenabled: request.$systemHelper.getSystemSetting( "ORM_SECONDARY_CACHE", false ),
cacheprovider : request.$systemHelper.getSystemSetting( "ORM_SECONDARY_CACHE", "ehCache" ),
logSQL : request.$systemHelper.getSystemSetting( "ORM_LOGSQL", false ),
sqlScript : request.$systemHelper.getSystemSetting( "ORM_SQL_SCRIPT", "" ),
// ORM SESSION MANAGEMENT SETTINGS, DO NOT CHANGE
flushAtRequestEnd : false,
autoManageSession : false,
// ORM EVENTS MUST BE TURNED ON FOR CONTENTBOX TO WORK DO NOT CHANGE
eventHandling : true,
eventHandler : "cborm.models.EventHandler",
// THIS IS ADDED SO OTHER CFML ENGINES CAN WORK WITH CONTENTBOX
skipCFCWithError : true,
// TURN ON FOR Debugging if ORM mappings are not working.
savemapping : false
};this.ormSettings = {
// ...
namingStrategy : "models.orm.UnderscoreNamingStrategy"
}// models/orm/UnderscoreNamingStrategy.cfc
component{
function getTableName( string tableName ){
// funky table name conversion here...
}
function getColumnName( string columnName ){
// funky column name conversion here...
}
}none : Does not change the database at all.property name="Contact"
fieldtype="one-to-one"
cfc="Contact";property name="Contact"
fieldtype="one-to-one"
cfc="Contact"
lazy="false";component entityName="User" persistent="true"{
property name="posts"
fieldtype="one-to-many"
cfc="Post";
}property name="posts"
fieldtype="one-to-many"
cfc="Post"
lazy="true";component entityName="Post" persistent="true"{
property name="Authors"
fieldtype="many-to-one"
cfc="User";
}component entityName="User" persistent="true"{
property name="posts"
fieldtype="many-to-many"
cfc="Post"
linktable="user_posts_link";
}property name="posts"
fieldtype="many-to-many"
cfc="Post";
linkschema="blog"
linkcatalog="dbo";property name="Authors"
singularName="Author"
fieldtype="many-to-one"
cfc="User";property name="posts"
fieldtype="one-to-many"
cfc="Post"
lazy="true";property name="posts"
fieldtype="one-to-many"
cfc="Post"
lazy="extra";Learn the basics of modeling ORM entities
component persistent="true"{
}component persistent="true" entityname="Author" {
}component persistent="true" entityname="Author" table="authors" {
}