Search code examples
javahibernategwtgilead

Persist classes with inheritance using Gilead


I'm using Gilead to persist my entities in my GWT project and I've run into an issue. I'd like to create a parent class to hold some properties that are common throughout my entities (id, etc). When persisting I get a null pointer exception.

Parent class:

public abstract class Entity extends LightEntity implements Serializable {
    protected Long id;
    public Entity(){}
}

Child class:

public class Person extends Entity  {
    private String firstName;
    private String lastName;
    public Person(){}
}

Hibernate mapping file:

<hibernate-mapping>
    <class name="com.domain.Entity" abstract="true" >
        <id name="id" type="long">
                <column name="ID"/>
                <generator class="native" />
            </id>
        <union-subclass name="com.domain.Person" table="PERSON">
            <property name="id" type="long" />
            <property name="firstName" type="string">
                <column name="FIRST_NAME" length="45" not-null="true" />
            </property>
            <property name="lastName" type="string">
                <column name="LAST_NAME" length="45" not-null="true" />
            </property>
        </union-subclass>
    </class>
</hibernate-mapping>

Stack trace when persisting:

java.lang.NullPointerException at net.sf.gilead.gwt.PersistentRemoteService.processCall(PersistentRemoteService.java:170) at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:86) at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214) at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380) at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265) at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)


Solution

  • Are you using Gilead < 1.2.2?

    If yes, upgrade Gilead. And then run again and check the new exception message. Most likely just some kind of misconfiguration.

    Full explanation:

    If you check the source code of PersistentRemoteService.java in version 1.2.1

    PersistentRemoteService.java v1.2.1

    at line 170 you see the following line

    return RPCCopy.getInstance().encodeResponseForFailure(null, ex, rpcRequest.getSerializationPolicy());
    

    This obviously fails with a NullPointerException if rpcRequest is null.

    That happens when in line 143

    // Decode request
    rpcRequest = RPCCopy.getInstance().decodeRequest(payload, this.getClass(), this);
    

    The decodeRequest-Method throws an IncompatibleRemoteServiceException. Which it does in your case.

    Starting with version 1.2.2 the line 170 changes to

    if (rpcRequest != null)
    {
      return RPCCopy.getInstance().encodeResponseForFailure(null, ex, rpcRequest.getSerializationPolicy());
    }
    else
    {
        return RPCCopy.getInstance().encodeResponseForFailure(null, ex);
    }
    

    Now you should get the right exception (IncompatibleRemoteServiceException)which points you to the real problem.

    You can also check the corresponding commit/fix in SVN

    Bad exception fix (issue 2663344)

    and the corresponding issue entry in the Bug-Tracker for Gilead

    Wrong exception

    So this issue is solved in SVN since February 07 2009 or since Gilead version 1.2.2 (March 13 2009)