Is ORM supported by ColdFusion 11? - orm

Mapping Two cfc objects via ORM, on execution a Dump shows the data for only one parent cfc object for table=products while the array of cfc table=department is coming back as (empty string) in output .
<cfcomponent persistent="true" table="products" >
<cfproperty name="productID" column="id" fieldtype="id" type="numeric" generator="increment">
<cfproperty name="name">
<cfproperty name="price">
<cfproperty name="description">
<cfproperty name="imageurl">
<cfproperty name="departmt" fieldtype="many-to-one" cfc="departmt" fkcolumn="dept_id" lazy="true">
<cfcomponent persistent="true" table="department">
<cfproperty name="id" column="dept_id" fieldtype="id" type="numeric" generator="increment">
<cfproperty name="name" column="dept_name">
<cfproperty name="location" >
</cfcomponent>

Related

NHibernate 2nd level cache does not invalidate entities map on the same table

I'm using NHibernate 3.2 with appfabric 1.1 for the 2nd level cache.
I’ve 2 classes mapped on the same table. The first class AFullEntity (MonitorLayoutData in the sample), inherit a second class which is lightweight class (MonitorLayout). MonitorLayoutData contains a heavy property that is not present in the base class. For example :
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Entities.MonitorLayout,Entities" table="MonitorLayouts2" lazy="false" schema="dbo" polymorphism="explicit">
<cache usage="nonstrict-read-write"/>
<id name="Id" column="MonitorLayout_ID" type="int">
<generator class="native" />
</id>
<property name="Name" column="MonitorLayout" type="string" />
<property name="UserId" column="User_ID" type="int" />
<property name="IsPublic" column="IsPublic" type="Boolean" not-null="true" />
<property name="ViewGuid" column="ViewGuid" type="string" not-null="true" />
<property name="TreeNode" column="TreeNode" type="string" />
<property name="IncludeNodeChildren" column="IncludeNodeChildren" type="Boolean" />
</class>
<class name="Entities.MonitorLayoutData,Entities" table="MonitorLayouts2" lazy="false" schema="dbo" polymorphism="explicit">
<cache usage="nonstrict-read-write"/>
<id name="Id" column="MonitorLayout_ID" type="int">
<generator class="native" />
</id>
<property name="Name" column="MonitorLayout" type="string" />
<property name="UserId" column="User_ID" type="int" />
<property name="IsPublic" column="IsPublic" type="Boolean" not-null="true" />
<property name="ViewGuid" column="ViewGuid" type="string" not-null="true" />
<property name="TreeNode" column="TreeNode" type="string" />
<property name="IncludeNodeChildren" column="IncludeNodeChildren" type="Boolean" />
<property name="LayoutData" column="LayoutData" type="BinaryBlob" not-null="false"/>
</class>
</hibernate-mapping>
Those classes use an explicit polymorphism to retrieve only entities for the selected type like note in the documentation : “Explicit polymorphism is useful when two different classes are mapped to the same table (this allows a "lightweight" class that contains a subset of the table columns)”.
However I got a problem when entities are cached. When I update a AFullEntity changes are not report in the lightweight class and this is a big problem for us.
I try other mechanism like subclass or extends but NHibernate force me to declare a discriminator element, which is not required for me.
Is there a way to do this ?
No, they are two separate objects, each with their own identity in the cache. Possible workaround would be to disable caching for lightweight objects or evict the lightweight object from the cache when the heavy object is loaded. Loading the heavy and light objects in the same session seems to me to defeat the purpose.

How do I get at join table properties when using ColdFusion ORM?

I have two objects, Person and Family. I use a join table called "join_person_family" to track this many-to-many relationship. The join table has another property called "IS_PRIMARY" that I want to get at and filter when instantiating the person objects with EntityLoadByExample(), but I don't know how to do this with CF ORM. I could do this easily through SQL, but I'm trying to use ORM as much as possible. There may also be another way to track this property, but I can't think of anything. Thanks in advance for any help.
Here is the Family.cfc:
<cfcomponent hint="I am a Family" output="false" persistent="true" extends="_Proxy">
<cfproperty name="FAMILY_ID" hint="FAMILY_ID" type="numeric" ormtype="int" length="11" fieldtype="id" generator="identity" required="true"/>
<cfproperty name="PERSON" hint="PERSON" fieldtype="many-to-many" cfc="person" linktable="join_family_person" FKColumn="FAMILY_ID" inversejoincolumn="PERSON_ID" lazy="true"/>
<cfproperty name="STATUS" type="string" ormtype="string" length="45"/>
<cfproperty name="COMMENT" hint="COMMENT" type="string" length="255"/>
<cffunction name="init" hint="constructor" access="public" returntype="family" output="false">
<cfscript>
return this;
</cfscript>
</cffunction>
</cfcomponent>
Here is the Person.cfc:
<cfcomponent hint="I am a Person" output="false" persistent="true" extends="_Proxy">
<cfproperty name="FAMILY" hint="FAMILY" fieldtype="many-to-many" cfc="family" linktable="join_family_person" FKColumn="PERSON_ID" inversejoincolumn="FAMILY_ID" lazy="true"/>
<cfproperty name="PERSON_ID" hint="PERSON_ID" type="numeric" ormtype="int" length="11" fieldtype="id" generator="identity" required="true"/>
<cfproperty name="USER" hint="USER" fieldtype="one-to-one" cfc="mend_user" FKColumn="USER_ID" lazy="true"/>
<cfproperty name="FIRST_NAME" hint="FIRST_NAME" type="string" length="45"/>
<cfproperty name="LAST_NAME" hint="LAST_NAME" type="string" length="45"/>
<cfproperty name="STATUS" hint="STATUS" type="numeric" ormtype="int"/>
<cffunction name="init" hint="constructor" access="public" returntype="person" output="false">
<cfscript>
return this;
</cfscript>
</cffunction>
Found this response, https://groups.google.com/forum/?hl=en&fromgroups=#!topic/cf-orm-dev/6Fox77MAcbs. After reading that I think that approach is actually superior anyway.
A intermediate entity with many-to-one relationships with the joining objects would allow me to use EntityLoadByExample() to get the relevant person objects filtered by "IS_PRIMARY". Then I could filter the person objects if need be.

NHibernate create IMAGE instead VarBinary(max)

I use the fallowing NHibernate Mapping (NH 3.2) with MS SQL Server 2008 (set MsSql2008Dialect):
<class name="Layout" table="Layout" lazy="false" >
<cache usage="read-write"/>
<id name="Id" column="Id" type="Guid">
<generator class="assigned"/>
</id>
<version name="ObjectVersion" column="ObjectVersion"/>
<property name="Key" column="Key" type="String" length="255" not-null="true" />
<property name="Value" column="Value" type="BinaryBlob" length="2147483647" />
<property name="Created" column="Created" type="Timestamp" not-null="true" optimistic-lock="false" />
<property name="CreatedBy" column="CreatedBy" type="String" length="255" not-null="true" optimistic-lock="false" />
<property name="Changed" column="Changed" type="Timestamp" optimistic-lock="false" />
<property name="ChangedBy" column="ChangedBy" type="String" length="255" optimistic-lock="false" />
<many-to-one name="User" class="User" foreign-key="FK_User_Layout" lazy="proxy" fetch="select">
<column name="UserId"/>
</many-to-one>
</class>
The Problem is here, that for the Column Value, NHibernate will create a Field of IMAGE. But I need VarBinary(max). What is wrong with the mapping?
I have the same problem after migration from version 3.1 to 3.2.
I think this is a bug.
I have explored source code version 3.1 and 3.2 and have found some difference which changed initialization sequence for MsSqlDialect* classes.
I fixed it by creating descendant of dialect class and overriding method "RegisterLargeObjectTypeMappings"
public class MyMsSql2008Dialect : MsSql2008Dialect
{
protected override void RegisterLargeObjectTypeMappings()
{
base.RegisterLargeObjectTypeMappings();
base.RegisterColumnType(DbType.Binary, 2147483647, "VARBINARY(MAX)");
}
}
Try this
<property name="Value">
<column name="Value" sql-type="varbinary(max)" />
</property>

HQL: query only base table from <join> entity

I have this mapping
<class name="Person" table="person">
<id name="Id" column="id" type="Int32" unsaved-value="0">
<generator class="native" />
</id>
<property name="Code" column="code" type="String" not-null="true" />
<property name="FirstName" column="firstName" type="String" not-null="true" />
<property name="MiddleName" column="middleName" type="String" not-null="false" />
<property name="LastName" column="lastName" type="String" not-null="false" />
<join table="personPhoto" optional="true">
<key column="personId" />
<property name="Photo" column="pictureContent" not-null="false" />
</join>
and the generated SQL always use left outer join, which is correct.
However, is it possible to tell HQL to query only from person table, since I'm not always need 'Photo' property? And how?
Is there a one-to-one relationship between person and personPhoto columns?
If you want to load the person's photo lazily, I believe you have to change join mapping to one-to-one mapping and create a new class for personPhoto. This way Hibernate would be able to insert a proxy object.

ColdFusion9 orm properties in script

I'd like to write the following in script syntax rather than the old style tag syntax.
<cfcomponent persistent="true" table="AuditType" schema="Audit" >
<cfproperty name="AuditTypeID" column="AuditTypeID" ormtype="int" fieldtype="id" />
<cfproperty name="AuditTypeName" column="AuditTypeName" ormtype="string" />
<cfproperty name="AuditTypeSort" column="AuditTypeSort" ormtype="integer" />
</cfcomponent>
the cfscript syntax really is quite similar,
component persistent="true" table="AuditType" schema="Audit" {
property name="AuditTypeID" column="AuditTypeID" ormtype="int" fieldtype="id";
property name="AuditTypeName" column="AuditTypeName" ormtype="string";
property name="AuditTypeSort" column="AuditTypeSort" ormtype="integer";
}