Error when using hibernate and datasource .ds.xml

Hi
I’m using Smart GWT version 2.4.
I get an exception (documented at the bottom) when using the following datasource definition:

<DataSource
    ID="companyGroup"
    serverType="hibernate"
    schemaBean="za.co.bookaservice.domain.CompanyGroup">
    <fields>
        <field name="companyGroupId"     title="Company Group ID"   primaryKey="true" />
        <field name="companyGroupName"   title="Company Group Name"/>
        <field name="ltGenStatus"        hide="true"/>
    </fields>
</DataSource>

I have attached the CompanyGroup.java bean class and hbm.xml - these were generated like this. I did try to add annotations to the bean class as well - did not work.

When I change the datasource as follows:

<DataSource
    ID="companyGroup"
    serverType="hibernate"
    tableName="company_group">
    <fields>
        <field name="companyGroupId"     title="Company Group ID"   primaryKey="true" />
        <field name="companyGroupName"   title="Company Group Name"/>
        <field name="ltGenStatus"        hide="true"/>
    </fields>
</DataSource>

It works better - but then I the JS goes into a recursive mode of trying to return data. The forums suggested that I use dropExtraFields=“true”. But to use this, I have to use schemaBean.

Please help. I’m stuck here.

Exception generated by top datasource definition:

=== 2011-08-05 13:22:41,752 [main] INFO PreCache - Isomorphic PreCache complete (386ms)
=== 2011-08-05 13:22:47,575 [l0-2] DEBUG XML - Parsed XML from C:\Dev\workspace\HibernateDS\war\ds\companyGroup.ds.xml: 1ms
=== 2011-08-05 13:22:47,615 [l0-3] INFO Download - Returning 304: Not modified on conditional get of: C:\Dev\workspace\HibernateDS\war\hibernateds\sc\skins\Enterprise\load_skin.js
=== 2011-08-05 13:22:47,670 [l0-2] DEBUG XML - Parsed XML from (in memory stream): 3ms
=== 2011-08-05 13:22:49,609 [l0-2] INFO HibernateDataSource - dynamically binding entity: companyGroup
=== 2011-08-05 13:22:49,946 [l0-2] DEBUG XML - Parsed XML from (in memory stream): 1ms
=== 2011-08-05 13:22:49,947 [l0-2] ERROR DataSourceLoader - Exception while attempting to load a DataSource
java.lang.NullPointerException
at org.hibernate.mapping.PersistentClass.createPrimaryKey(PersistentClass.java:316)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:379)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:295)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:166)
at org.hibernate.cfg.Configuration.add(Configuration.java:702)
at org.hibernate.cfg.Configuration.addDocument(Configuration.java:517)
at com.isomorphic.hibernate.HibernateDataSource.init(HibernateDataSource.java:220)
at com.isomorphic.datasource.BasicDataSource.fromConfig(BasicDataSource.java:165)
at com.isomorphic.datasource.DataSource.fromConfig(DataSource.java:337)
at com.isomorphic.hibernate.HibernateDataSource.fromMappedClass(HibernateDataSource.java:1766)
at com.isomorphic.hibernate.HibernateDataSource.init(HibernateDataSource.java:146)
at com.isomorphic.datasource.BasicDataSource.fromConfig(BasicDataSource.java:165)
at com.isomorphic.datasource.DataSource.fromConfig(DataSource.java:337)
at com.isomorphic.datasource.FileSystemDSRepo.loadDS(FileSystemDSRepo.java:110)
at com.isomorphic.datasource.DataSource.forName(DataSource.java:156)
at com.isomorphic.datasource.DataSource.forName(DataSource.java:148)
at com.isomorphic.datasource.DataSource.forName(DataSource.java:143)
at com.isomorphic.datasource.PoolableDataSourceFactory.makeUnpooledObject(PoolableDataSourceFactory.java:95)
at com.isomorphic.datasource.PoolableDataSourceFactory.makeObject(PoolableDataSourceFactory.java:102)
at com.isomorphic.pool.PoolManager.borrowObject(PoolManager.java:82)
at com.isomorphic.datasource.DataSourceManager.getDataSource(DataSourceManager.java:62)
at com.isomorphic.servlet.DataSourceLoader.processRequest(DataSourceLoader.java:81)
at com.isomorphic.servlet.DataSourceLoader.doGet(DataSourceLoader.java:64)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
=== 2011-08-05 13:22:49,948 [l0-2] ERROR DataSourceLoader - Top-level servlet error:
javax.servlet.ServletException: java.lang.NullPointerException
at org.hibernate.mapping.PersistentClass.createPrimaryKey(PersistentClass.java:316)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:379)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:295)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:166)
at org.hibernate.cfg.Configuration.add(Configuration.java:702)
at org.hibernate.cfg.Configuration.addDocument(Configuration.java:517)
at com.isomorphic.hibernate.HibernateDataSource.init(HibernateDataSource.java:220)
at com.isomorphic.datasource.BasicDataSource.fromConfig(BasicDataSource.java:165)
at com.isomorphic.datasource.DataSource.fromConfig(DataSource.java:337)
at com.isomorphic.hibernate.HibernateDataSource.fromMappedClass(HibernateDataSource.java:1766)
at com.isomorphic.hibernate.HibernateDataSource.init(HibernateDataSource.java:146)
at com.isomorphic.datasource.BasicDataSource.fromConfig(BasicDataSource.java:165)
at com.isomorphic.datasource.DataSource.fromConfig(DataSource.java:337)
at com.isomorphic.datasource.FileSystemDSRepo.loadDS(FileSystemDSRepo.java:110)
at com.isomorphic.datasource.DataSource.forName(DataSource.java:156)
at com.isomorphic.datasource.DataSource.forName(DataSource.java:148)
at com.isomorphic.datasource.DataSource.forName(DataSource.java:143)
at com.isomorphic.datasource.PoolableDataSourceFactory.makeUnpooledObject(PoolableDataSourceFactory.java:95)
at com.isomorphic.datasource.PoolableDataSourceFactory.makeObject(PoolableDataSourceFactory.java:102)
at com.isomorphic.pool.PoolManager.borrowObject(PoolManager.java:82)
at com.isomorphic.datasource.DataSourceManager.getDataSource(DataSourceManager.java:62)
at com.isomorphic.servlet.DataSourceLoader.processRequest(DataSourceLoader.java:81)
at com.isomorphic.servlet.DataSourceLoader.doGet(DataSourceLoader.java:64)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)

at com.isomorphic.servlet.DataSourceLoader.processRequest(DataSourceLoader.java:89)
at com.isomorphic.servlet.DataSourceLoader.doGet(DataSourceLoader.java:64)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)

Uploaded the files promised.

CompanyGroup.hbm.xml (1.99 KB)

CompanyGroup.java (3.01 KB)

You don’t need to use schemaBean to be able to use dropExtraFields=“true”, so that solves your problem. As far as the exception, it’s not clear what’s causing Hibernate to blow up (possibly the use of a Short as a primary key?) but please let us know if the problem is still there with 2.5.

Thanks.
I’ve changed my data source to:

<DataSource
    ID="companyGroup"
    serverType="hibernate"
    tableName="company_group"
    dropExtraFields="true">
    <fields>
        <field name="companyGroupId"     title="Company Group ID"   primaryKey="true" />
        <field name="companyGroupName"   title="Company Group Name"/>
        <field name="ltGenStatus"        hide="true"/>
    </fields>
</DataSource>

Now, I go past the primary key exception, but still gets an explosion of the following messages until the JVM runs out of heap:

JSTranslater - za.co.bookaservice.domain.UserDetail contains a (potentially indirect) looping reference to itself. Returning null for recursed value.

I’m busy upgrading to Smart GWT 2.5 - although I bought Smart GWT 2.4 Pro, I’m not allowed to download the upgrade. I’m taking up this with your sales team.

Well, you’ve got a field “ltGenStatus” represented by an arbitrary bean for which you haven’t provided source code. That bean could well reference everything else in the system, hence introducing runaway serialization. Generally, you want to set things up so you’re only sending atomic types or nested records consisting of atomic types. See also DataSourceField.valueXPath and the ability to set the type of a field to the ID of a related DataSource if you want to send a nested data structure (not commonly useful).

Brilliant - this worked!
The upgrade changed nothing in the behavior.

I’ve added DataSourceField.valueXPath to the ltGenStatus field to retrieve the singular value.

Thanks - your help is much appreciated.