Posted in ColdFusion | Posted on 02-08-2010 | 2,245 views
This afternoon I was working on a set of persistent entities called event, eventtype, eventstatus, and eventpriority. Event is the "core" entity with hooks to status, type, and priority. When everything was done I whipped up a quick test:
I assumed this would work - or throw an error about one of the properties perhaps. What I did not expect was this:
Mapping for component event not found.
That made no sense. I took a quick look at the Hibernate APIs to see if there was a simple way to list all known entities. I discovered getAllClassMetadata, a method of the SessionFactory, and quickly tried the following code:
2<cfset known = listSort(structKeyList(factory.getAllClassMetadata()),"textnocase")>
3<cfoutput>#known#</cfoutput>
This returned a nice list of entities - which unfortunately did not include event. At this point I was completely stumped. I had - of course, ran an ormReload() on my application. I even ran an applicationStop(). None of them threw an error, but none of them made event become recognized. Then I decided to check my ColdFusion logs. I found this gem in application.log:
"Skipping file c:\yada\yada\yada\event.cfc as it has errors"
What the frack?!?! So the component had an error - and the ORM system noticed this and just didn't tell me? How incredibly frustrating and counterintuitive! I checked exception.log and luckily, it had a longer error. My stack trace said:
"Properties cannot be declared more than once."
I quickly went back to event.cfc and saw the error right away - two properties with the same name. -sigh- Fixing that immediately corrected my problem.


I'm assuming the "Skipping file c:\yada\yada\yada\event.cfc as it has errors" log entry was written when the event.cfc was being checked to see if it were a persistent entity. Since it couldnt compile (and therefore pull the metadata), it was skipped just in case it wasn't relevant to the current request.
The fact of the matter is, you shouldn't be stopped from running the app because of an error'd file that's not even part of the request... that'd be very confusing and frustrating.
In any case, you're a bit late, for this was discussed quite a bit in beta...
As for TDD CFCs - are they persistent="true"? I'd be surprised if so.
"The fact of the matter is, you shouldn't be stopped from running the app because of an error'd file that's not even part of the request... that'd be very confusing and frustrating.
In any case, you're a bit late, for this was discussed quite a bit in beta..."
Seems to me, your file is part of your application and the part about being discussed in beta, is totally without merrit. That is as childish as saying 'My dad can write better code than your dad.'
Ray, It doesn't matter. I'm saying that ANY CFC (persistent or not) with an error would cause the entire app to not run at all. The CFC must be compiled in order to pull the metadata to even check if it's persistent or not. If it compile it to make that check, and doesn't skip it, it should bring down everything else?
"consider the _normal_ developer. S/he is going to have no idea why his entity doesn't work"
That's what the logs are for, right? Is it not standard practice to check the logs when you can't figure something out? Do you think a _normal_ developer will understand why running index.cfm throws an exception because SomeOrphaned.cfc (which is never executed anyway) has an error?
@Gary: If you believe that every file would be part the application, then my dad probably can write better code than your dad.
The file may or may not be part of the application. If you don't make use of the Application's cfclocation setting, then it scans the entire web root for persistent CFCs. Many people run multiple applications in the same web root (especially when you have no choice, like in shared hosting).
Think of these situations:
You're running your main site as well as BlogCFC, Lighthouse Pro, and a few other mini apps in your webroot. BlogCFC happens to have a syntacticly bad CFC in there somewhere, which rarely gets executed, and therefore wasn't an obvious bug to catch (not that Ray ever writes bugs). Because of that, it brings down the main web site, the bug tracker, and everything else you have running in that webroot.
A lot of people use their CF account to host test scripts, demos and even a playground area. Their production apps would probably all be toast in that situation.
I wasn't trying to be anonymous. Ray has my email, and I'm assuming he knows who I am (maybe not). I think I met you at the Denver Flex User Group awhile back (I'm the co-manager). Or was it the Denver CFUG...
And maybe I am wrong, but I would prefer it throw an error and let me comment it out or fix the error. And let us not forget that a lot of programmers don't have access to the logs on production servers, even test servers. At my shop, I am the only one that has access to the logs for security reasons. I'm not saying that is the corredt way, just the way it is.
When I use ORM, yes, I'd be willing for any 'bad' CFC to break the app. Yes, I would. :)
To your example - how would a bad BlogCFC bring down a bad LHP? By default, ORM apps check the current folder and subfolders under it. So subfolder A would not bring down subfolder B. And guess what - if subfolder A killed parent folder X, and if it was obvious, I'd know immediately how to fix it. I'd comment out the CFC. Problem solved.
Imagine this filesystem structure:
shinynet (webroot)
-- Application.cfc (for main site - ormEnabled)
-- index.cfm (and rest of main site files)
-- blog
---- Application.cfc (for blogcfc)
---- BadFile.cfc (can't be compiled due to error)
Requests to shinynet.com/index.cfm (or any request to the main site) would throw an error because of the blog.BadFile CFC, even though a request wasn't being made to the blog.
I know you believe that it'd be quicker to just fix any problems that are unrelated to the code you're trying to run, but the idea of having a piece of logic so dependant on other files that have absolutely no relation to it, and not even part of the same request, smells horribly, horribly wrong.
Just my opinion and I'm glad things were changed to work the way they do.
At this point - I'm done. I'm right. You're wrong. I'm rubber. You're glue. Etc. ;)
Thanks to both of you.
So this is something that is worth re-consideration. We might just take a middle ground instead of reverting it completely.
Also don't forget you can enable logging for Hibernate. That will "unhide" the SQL.
However, doing the some bare minimum testing of the CFC, such as running a quick CreateObject() on to make sure it's able to be instantiated would avoid this type of problem.
I liek the fact that ORM can handle much of the database work, but let me tell it what to do.
[Add Comment] [Subscribe to Comments]