1

尝试使用 County 扩展 Unit 时发生错误,特别是在重新启动应用程序以初始化 ORM 时。[注意:我正在尝试单表继承]

ORM 正在管理我的数据库模式:this.ormsettings.dbcreate=dropcreate

当我从模型目录中删除 County.cfc 时,ORM 初始化并且应用程序正常启动。当我将 County.cfc 放回模型目录时,错误再次出现。

ColdFusion 版本 10,282462 MSSQL IIS

单元:

<cfcomponent persistent="true" entityname="Unit" table="Units" discriminatorColumn="type">
    <cfproperty name="id" fieldtype="id" column="unit_id" generator="identity">  
    <cfproperty name="name" default="" type="string" length="50"> 
    <cfproperty name="description" type="string" sqltype="varchar(max)" default="">
    <cfproperty name="active" type="boolean" default="true"> 
</cfcomponent>

县:

<cfcomponent persistent="true" entityname="County" table="Units" extends="Unit" discriminatorValue="county">
    <cfproperty name="officeAddress" type="string">
</cfcomponent>

堆栈跟踪:

java.lang.NullPointerException at
org.hibernate.mapping.PersistentClass.createPrimaryKey(PersistentClass.java:322) at
org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:405) at
org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:321) at
org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:172) at
org.hibernate.cfg.Configuration.add(Configuration.java:771) at
org.hibernate.cfg.Configuration.addDocument(Configuration.java:586) at
coldfusion.orm.hibernate.HibernateConfiguration.buildConfiguration(HibernateConfiguration.java:611) at
coldfusion.orm.hibernate.HibernateConfiguration.initHibernateConfiguration(HibernateConfiguration.java:208) at
coldfusion.orm.hibernate.HibernateConfiguration.<init>(HibernateConfiguration.java:181) at
coldfusion.orm.hibernate.ConfigurationManager.initConfiguration(ConfigurationManager.java:67) at
coldfusion.orm.hibernate.HibernateProvider.InitializeORMForApplication(HibernateProvider.java:185) at
coldfusion.orm.hibernate.HibernateProvider.onPageRequestStart(HibernateProvider.java:151) at
coldfusion.filter.ApplicationFilter.firePageRequestStart(ApplicationFilter.java:599) at 
coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:407) at
coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48) at
coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40) at
coldfusion.filter.PathFilter.invoke(PathFilter.java:112) at
coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94) at
coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:79) at
coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) at
coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38) at
coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46) at
coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38) at
coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22) at
coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62) at
coldfusion.CfmServlet.service(CfmServlet.java:204) at
coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at
coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224) at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928) at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:414) at
org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:203) at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539) at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298) at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at
java.lang.Thread.run(Thread.java:662) 

奇怪的是,我已经在与另一个实体做类似的事情(DiscussionPost 扩展了 Post):

邮政:

<cfcomponent persistent="true" entityname="Post" table="Posts" discriminatorColumn="type">
    <cfproperty name="id" fieldtype="id" column="post_id" generator="identity">
    <cfproperty name="promotions" fieldtype="one-to-many" cfc="PostPromotion" fkcolumn="post_id" singularname="promotion">
    <cfproperty name="comments" fieldtype="one-to-many" cfc="PostComment" fkcolumn="post_id" singularname="comment">    
    <cfproperty name="user" fieldtype="many-to-one" cfc="User" fkcolumn="user_id">
    <cfproperty name="text" type="string" sqltype="varchar(1000)">
    <cfproperty name="timestamp" type="date" ormtype="timestamp">
</cfcomponent>

讨论帖:

<cfcomponent persistent="true" entityname="DiscussionPost" table="Posts" extends="Post" discriminatorValue="discussionpost">
    <cfproperty name="discussion" fieldtype="many-to-one" cfc="Discussion" fkcolumn="discussion_id">
    <cfproperty name="title" type="string" sqltype="varchar(200)">

</cfcomponent>

我错过了什么?

4

3 回答 3

1

看起来您可能缺少 County.cfc 中 officeAddress 属性的 sqltype 属性

这能解决你的问题吗?

于 2012-08-04T01:58:17.850 回答
1

看起来这可能是您遇到的问题:https ://hibernate.onjira.com/browse/HBX-54

我认为解决方法是向 County.cfc 添加一个 id 属性:

<cfproperty name="id" fieldtype="id" column="county_id" generator="identity">

上面的代码假定您的 id 列名为“county_id”。这能解决你的问题吗?

于 2012-08-14T03:43:50.160 回答
0

好的。事实证明,这个问题的答案非常简单。通过在我的代码库上进行全局搜索和替换,将“单元”替换为“容器”,我能够让我的应用程序中的单表继承正常工作。严重地。这就是我所做的所有改变,并且奏效了。'Unit' 显然不是 CF 中的保留字,因为实体独立Unit工作,但它一定在某些内部过程中引起了问题(可能getColumnIterator()正如@MikeCauser 所建议的那样)。

感谢大家的建议。

编辑:结果证明这是一个偶然的修复,而不是针对问题根源的修复,无论它可能是什么。真正的解决方案还有待找到。

编辑 2:我现在确信手头的问题与 ColdFusion/Hibernate 内部有关,只需重新启动 ColdFusion 服务即可刷新。

是的,在我的头在我的办公桌上不停地敲了两个星期之后,我重新启动了 ColdFusion 应用程序服务,我的问题就解决了。从那时起,我已经将容器组件扩展了 3 次。一切看起来都很好,我已经继续我的申请了。

于 2012-08-17T02:07:23.190 回答