Coldfusion ORM 9.0.1 - Error while resolving relationship - orm

I got this example from the adobe coldfusion documentation, some of the names are changed but everything else is the same, unless I am just so frustrated that I have missed a letter.
user.cfc:
/**
*#persistent
*/
component
{
property name="id" fieldtype="id" generator="native";
property name="userName" type="string" length="100";
property name="Credential" fieldtype="one-to-one" cfc="model.user.credentials";
}
credentials.cfc:
/**
*#persistent
*/
component
{
property name="id" fieldtype="id" generator="foreign" params="{property='userinfo'}";
property name="userinfo" fieldtype="one-to-one" cfc="model.user.user" constrained="true";
property name="passwordHash" type="string";
}
no matter how I word it, after searching many sites, I still get a error of:
Error while resolving the relationship Credential in cfc user. Check the column mapping for this property.
I have checked that both cfcs are accessible by coldfusion by removing the one-to-one properties and the tables have been created successfully.
I am using SQL Server 2008 with Coldfusion 9.0.1 under Apache 2.2 web server.
I am new to ORM and Hibernate but have successfully created different types of relationships and will confess to a less then expert level of coldfusion.
Thanks, this is really bothering me as this came directly from the coldfusion documentation.

Do you have a mapping for model?
If not, add one, or you could try:
property name="Credential" fieldtype="one-to-one" cfc="credentials";

Related

ColdFusion ORM - Mapping for component ARTISTS not found.

I am looking into ORM and started off with some tutorials from a pdf that I found on adobe's site. I created a folder under wwwroot called test.
here is my application.cfc
component {
this.name = "artGalleryApp" ;
this.ormenabled = true ;
this.datasource = "cfartgallery" ;
}
I have artists.cfc under wwwroot/test/model folder.
<cfcomponent persistent="yes" table="artists" entityname="giggidy">
<cfproperty name="id" column = "artistID" generator="increment">
<cfproperty name="firstName">
<cfproperty name="lastName">
<cfproperty name="address">
<cfproperty name="city">
<cfproperty name="state">
<cfproperty name="postalCode">
<cfproperty name="email">
<cfproperty name="phone">
<cfproperty name="fax">
<cfproperty name="thePassword">
</cfcomponent>
Then, I have an index.cfm with the following:
artists = EntityLoad("ARTISTS") ;
writeDump(artists) ;
When I run this, I get :
Mapping for component ARTISTS not found.
Either the mapping for this component is missing or the application must be restarted to generate the mapping.
I restarted CF application server, and this error went away. Do I have to restart CF appliction server every single time I create an ORM application?
Is it better to use model.ARTISTS or some other way to specify where this component is located?
Now, the biggest question. I always wrote stored procedures, packages, etc etc(SQL Server, Oracle) whenever I needed DML statements. I never included inline queries in my CF code. I also handled logging and error handling within these procs, packages, etc. etc.
If I had to make a change to the database structure, I would simply modify things on the database side. For this reason only, what would be the benefits of using ORM? I change a table add/remove a field, I have to go through CF code to make the necessary updates. Why?
Mapping for component ARTISTS not found because: entityname="giggidy"
so use EntityLoad("giggidy")
And use ORMReload() and you don't need to restart CF.

Could not find the property - exception after switching from NHibernate 3 to 3.3.1

I have a class with a field:
protected DateTime insertDate;
This is mapping for this fiels:
<property name="InsertDate" access="field.camelcase" update="false" />
This field is set when with ctor
public DocuBase(DateTime insertDate)
and is persisted only when row is added to the database. I don't need property for it at all, no setter & no getter. I worked in NHibernate 3.
And now, I've moved from NHiberbate 3 to NHibernate 3.3.1, and I get this exception when session factory is created:
Could not find the property 'InsertDate', associated to the field
'insertDate', in class 'XXXX'
Why is is happening & how can I change mapping in order to get rid of the exception?
EDIT: Below answer is completly correct. But for those of you that don't need/don't want to have a property, and only field, there's another solution:
set name attribute to field name (in my case it is insertDate) and remember to have correct column name
<property name="insertDate" column="InsertDate" access="field.camelcase" update="false" />
It is case sensitivity, this will work.
<property name="insertDate" column="InsertDate" update="false" />
Looks like in release 3.1.0, there was a breaking change
NH today accepts code below. It would be better if this would throw - it causes problem when configurate NH (or 3rd party tools) other ways than by hbm, using the property name (or memberinfo) of the public interface.
[hbm]
<property name="Name" access="field.camelcase" />
[code]
string name;
public virtual string SomeThingCompletelyDifferent{
get {return name;}
set{name=value;}
}
Note: This will be a breaking change.
ps - updated answer to remove reference to use Property with private set as this was not what was being looked for and above breaking change is more relevant.

Coldfusion ORM Macromedia][Oracle JDBC Driver][Oracle]ORA-02289: sequence does not exist

I have a ColdFusion ORM application that uses an oracle sequence as the generator for the primary key field. I have verified that I can access the sequence as the user that ColdFusion is connected to the database as in SQL navigator.
My problem is I am getting the following error when I attempt to saveEntity() on any object
Root cause :java.sql.SQLException: [Macromedia][Oracle JDBC Driver][Oracle]ORA-02289: sequence does not exist
I have tried the syntax below with and without the akc. prefix. I do have the akc schema defined in the CFC
<cfproperty name="KEY_BREED_PAGE" fieldtype="id" generator="sequence" params="{sequence='akc.seq_breed_page_display'}" />
and
<cfproperty name="KEY_BREED_PAGE" fieldtype="id" generator="sequence" sequence="akc.seq_breed_page_display" />
Any ideas on what I can do to resolve this? The ORM works fine when updating but fails on every attempt to create a new record.
I had a similar when I didn't have the schema. The only difference between your example and mine is that I have the column attribute set.
<cfproperty name="KEY_BREED_PAGE" fieldtype="id" column="KEY_BREED_PAGE" generator="sequence" sequence="akc.seq_breed_page_display" />

using Nhibernate lazy proxys with a webservice

Recently i had some performance problems in a SOAP webservice I wrote a while ago. I noticed I had a lot of queries going on and my hbm.xml mappings where full of lazy=false statements. I upgraded to NHibernate 3.0 and removed the lazy = false stuff and everything was a LOT faster....but now i am getting the following error:
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type UserProxy was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
User is a class of which i removed the lazy=false property from the class tag like this:
<class name="User" table="Users" >
<id name="DatabaseID" unsaved-value="0" column="ID" type="integer" >
<generator class="native"/>
</id>
<property name="IsExpert"/>
.....more stuff here....
</class>
My webservice has a method like this (simplified a little..in real-life i use a repository-like pattern between the service and nhibernate):
[WebMethod]
public User GetUser(int userid)
{
session = GetCurrentSession();
return session.Load<User>(userid);
}
The webservice expects to serialize a user and NHibernate gives me a UserProxy (which is not a user exactly). How should I overcome this?
Don't return entities from the web method. Use a DTO.
Webservices cannot serialise proxies - session.Load(userId) will return a proxy. You should user session.Get(userId) .
I think the answers saying you should use DTOs are not helpful, there is a time and place for DTOs and sometimes you may just want to return the entity.
If the User has child proxy properties, I have a class for handling this situation. Basically it loops through all properties (using reflection, and recursively going through child objects and collections) and uses the NHibernate.IsInitialized to check whether the property is a proxy or the genuine article. If it is a proxy then it sets it to null, thus making it possible for WCF to serialise it.

NHibernate setting access="field.camelcase-underscore" fails in version 3

I have a solution that was created with NHib 1.2 which we're upgrading to NHib 3.0.
Our hbm file has the following property:
<property name="ContentId" column="ContentId" access="field.camelcase-underscore" />
The class doesn't have a ContentId property. This was working fine in NHib 1.2 but now we're getting getting the following exception:
Could not compile the mapping document: XXXX.Core.Domain.Video.hbm.xml ---> NHibernate.MappingException: Problem trying to set property type by reflection ---> NHibernate.MappingException: class Core.Domain.Video, Core, Version=1.0.0.29283, Culture=neutral, PublicKeyToken=null not found while looking for property: ContentId ---> NHibernate.PropertyNotFoundException: Could not find the property 'ContentId', associated to the field '_contentId', in class 'Core.Domain.Video'.
Why would this stop working? Is it still supported in NHib 3?
We have many many properties like this that we might need to add.
NHibernate greatly improved its error messaging and diagnostics in NH2.X and again in NH3.X. You are telling NHibernate that you have a property and you want to map it via field access to a field named by _camelCase convention. You don't have a property named ContentId and NHibernate is letting you know that you lied to it. :)
Try updating your mapping to:
<property name="_contentId" column="ContentId" access="field" />
You will need to update any HQL or Criteria queries to use _contentId rather than ContentId. Another option would be to add a private ContentId property.
I'd like to provide information which helped me answer this question:
http://groups.google.com/group/nhusers/browse_thread/thread/e078734a221c3c0c/ec8b873b385d4426?lnk=gst&q=field+camelcase+underscore#ec8b873b385d4426
In this link Fabio explains the same problem you are having like this:
This mapping
<property name="PositiveValue" access="field.camelcase-underscore" />
mean: For my property named "PositiveValue" you (NH) have to access to
the field; to discover which is the associated field you (NH) have to
use the strategy "camelcase-underscore".
If there is no property you can't use the accessor with a specific
strategy.
Which struck me as a little odd because it meant adding dummy, unused properties, just to make the nhibernate3 compiler happy. The underlying functionality is the same.