public void function onLoad(){
var setupPath = getDirectoryFromPath(getCurrentTemplatePath()) & “config\setup.xml”;
var installService = binder.getInjector().getInstance(“Install@security”);
// if a file named setup.xml exists in the config folder lets install some default data
if( fileExists(setupPath) ){
installService.setConfigPath(setupPath);
installService.setup();
}
}
public void function setup(){
var f = fileRead(getConfigPath());
try {
setConfigXML( xmlParse(f) );
} catch(any e){
log.error(“There was an error parsing the xml config file.”);
}
// we only want to add this data if there are no records
// this is only to add some dummy data to the database
if( userService.count() == 0 ){ //THIS ROW GENERATE ERRROR
setupUsers();
}
}
I got this error:
User is not mapped [select count(*) from User]
Cause org.hibernate.hql.ast.QuerySyntaxException
What about that object dump makes you think that the ORM entity is in the CFCLocation? CFCLocation is part of the ORM settings that are defined in your Application.cfc in the root of your site.
> From my understanding autoMapModels automap all orm without using mappings.
No, the autoMapModels flag has nothing to do with ORM. It simply means that WireBox maps all the models in your module’s /models folder as “CFCName@ModuleName”. You can customize the “ModuleName” portion of that with the “this.modelNamespace” setting.
As for your issue, make sure this.ormSettings.CFCLocation includes the directory (or parent directory) where your ORM entity lives. Also, you may need to do an ORMReload when the module is installed to pick up new entities.
Also, note that ColdBox 4 is capable of adding app-specific ColdFusion mappings automatically that point to the root of your module. However, you probably can’t rely on those in your CFCLocation since they don’t get added until ColdBox starts processing each request so they don’t exist yet when Application.cfc is looking for ORM entities on startup.