Jonathan Wilson
Jonathan Wilson

Reputation: 4295

NullPointerException when extending persistent CFC

The error occurs when attempting to extend Unit with County, specifically, when restarting the application to initialize ORM. [Note: I'm attempting single-table inheritance]

ORM is managing my DB schema: this.ormsettings.dbcreate=dropcreate

When I remove County.cfc from the models directory, ORM initializes and the application starts normally. When I put County.cfc back into the models directory, the error occurs again.

ColdFusion version 10,282462 MSSQL IIS

Unit:

<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>

County:

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

StackTrace:

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) 

Odd thing is that I'm already doing something similar with another entity (DiscussionPost extends Post):

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>

DiscussionPost:

<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>

What am I missing?

Upvotes: 1

Views: 1569

Answers (3)

Jonathan Wilson
Jonathan Wilson

Reputation: 4295

OK. As it turns out, the answer to this was really very simple. By doing a global search and replace on my codebase, replacing 'unit' with 'container', I was able to get the Single Table Inheritance in my application to work correctly. Seriously. That's all I changed and it worked. 'Unit' is obviously not a reserved word in CF because the entity Unit works on its own but it must have been causing problems in some internal process (perhaps in getColumnIterator() as @MikeCauser suggested).

Thanks to all for your suggestions.

EDIT: This turned out to be an incidental fix, not a fix that targets the root of the problem, whatever that may be. A real solution remains to be found.

EDIT 2: I'm confident now that the issue at hand had to do with ColdFusion/Hibernate internals that simply needed to be refreshed by a restart of the ColdFusion service.

Yes, after banging my head against my desk off and on for two weeks, I restarted the ColdFusion Application Service and my problem was solved. I've extended the container component 3 more times since then. All appears well and I've moved on with my application.

Upvotes: 0

Russ
Russ

Reputation: 1951

It looks like this might be the issue you are experiencing: https://hibernate.onjira.com/browse/HBX-54

I think the fix is to add an id property to County.cfc:

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

The code above assumes that your id column is named "county_id". Does that fix your problem?

Upvotes: 1

Russ
Russ

Reputation: 1951

Looks like you might be missing the sqltype attribute for the officeAddress property in County.cfc

Does that solve your problem?

Upvotes: 1

Related Questions