问题描述
|
我刚开始在一个新项目上使用Hibernate,并且在我的第一个实体中出现了一个错误,似乎无法弄清。
我现在的模式只有两个表,大洲和国家(地区),其中国家/地区具有大洲外键。
当我尝试运行调用大洲实体的代码时,出现空白页。所有处理都将停止,但不会显示任何错误。当我通过MXUnit运行代码时,实际上收到一个错误。错误消息只是“ 0”。发生异常的原因是“ 1”。这就是我所得到的。
我的实际实体代码是:
Continent.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;
}
}
Country.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中
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\'];}
}
我找不到真正可以理解的有关错误消息的任何信息,因此这可能只是语法无效。
解决方法
问题是我使用了错误的属性来指定要在对象中映射的表名。该属性应为table = \'\',因此我的休眠对象应如下所示:
Continent.cfc
component table=\'continents\' persistent=true output=false{
}
Country.cfc
component table=\'countries\' persistent=true output=false{
}
, 表结构可能与java类中映射的表结构不同。
, 您的数据库架构是什么样的?我已经看到当对象中的数据类型与数据模型中的数据类型不一致时,会引发SQL Grammer执行。
, 您的数据库引擎是什么?
我们可以看到您的orm应用程序配置吗?
我个人从未见过属性ѭ7property,也没有在文档中找到它。
如果要强制使用数据类型,建议您使用\'sqlType\'
。通常我将它与datetime一起使用:
property name=\"creationDateTime\" type=\"date\" sqltype=\"datetime\";
我必须指定sqltype=\"datetime\"
,因为type=\"date\"
还不够。
, 确保配置“ 12”随数据类型一起显式提供。
例如,更改此:
<id name=\"id\" column=\"ID\"/>
对此:
<id name=\"id\" column=\"ID\" type=\"java.lang.Long\"/>