Dav*_*ong 0 coldfusion hibernate railo
我刚刚开始在一个新项目中使用 Hibernate,对于我的第一个实体,我遇到了一个错误,我似乎无法弄清楚。
我现在的架构只有两个表:大洲和国家,其中国家/地区有一个 ContinentalID 外键。
当我尝试运行调用大陆实体的代码时,我得到一个空白页面。所有处理都会停止,但不会显示任何错误。当我通过 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;
}
}
Run Code Online (Sandbox Code Playgroud)
国家.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;
}
}
Run Code Online (Sandbox Code Playgroud)
以及调用该方法的代码。它位于 ColdSpring bean 中
ContinentBean.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'];}
}
Run Code Online (Sandbox Code Playgroud)
我找不到任何关于我能理解的错误消息的信息,所以这可能只是一个无效的语法。
问题是我使用了错误的属性来指定要映射到对象中的表名称。该属性应该是 table='' 所以我的休眠对象应该如下所示:
大陆.cfc
component table='continents' persistent=true output=false{
}
Run Code Online (Sandbox Code Playgroud)
国家.cfc
component table='countries' persistent=true output=false{
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24840 次 |
| 最近记录: |