我刚开始在一个新项目中使用 Hibernate,在我的第一个实体中,我遇到了一个错误,我似乎无法弄清楚。
我现在的架构只有两个表,大陆和国家,其中国家有一个大陆外键。
当我尝试运行调用大陆实体的代码时,我得到一个空白页。所有处理都会停止,但不会显示错误。当我通过 MXUnit 运行代码时,我实际上得到了一个错误。错误信息很简单Could Not Load an Entity: [continent#1]
。异常的原因是org.hibernate.exception.SQLGrammarException
。这就是我得到的全部。
我的实际实体代码是:
大陆.cfc
component tablename='continents' persistent=true output=false{
property name='id' type='numeric' fieldtype='id' datatype='integer';
property name="name" type='string' length='45';
property name='bonus' type='numeric';
property name='countries' type='array' fieldtype='one-to-many' cfc='Country' singularname='country' inverse='true' fkcolumn='continentid' cascade='all-delete-orphan';
public Country function init(string name='', numeric bonus=0){
setName(Arguments.name);
return this;
}
}
国家.cfc
component tablename='countries' persistent=true output=false{
property name='id' type='numeric' fieldtype='id' datatype='integer' generator="identity";
property name="name" type='string' length='45';
property name='continent' fieldtype='many-to-one' fkcolumn='continentid' cfc='Continent' missingRowIgnored=true;
public Country function init(string name=''){
setName(Arguments.name);
return this;
}
}
以及调用该方法的代码。它在一个 ColdSpring bean 中
大陆豆.cfc
component {
property name="continent" type="any";
public any function init(any continent=''){
if(len(Arguments.continent))setContinent(Arguments.continent);
return this;
}
public any function getContinent(){
return continent;
}
public void function setContinent(numeric continent){
continent = EntityLoad('Continent', Arguments.continent, true);
}
public void function setMapService(mapService){variables.instance['mapService'] = Arguments.mapService;}
public any function getMapService(){return variables.instance['mapService'];}
}
我找不到任何关于我能理解的错误消息的真正信息,所以这可能只是一个无效的语法。