Gen EJB Web Service date attribute "NoSuchMethodException: java.sql.Date.<init>()"
search cancel

Gen EJB Web Service date attribute "NoSuchMethodException: java.sql.Date.<init>()"

book

Article ID: 431764

calendar_today

Updated On:

Products

Gen Gen - Run Time Distributed

Issue/Introduction

Gen 8.6 EJB Web Services under JBoss 7.4.23 with Java 11.

Some time ago this exception was being seen during SOAP calls, containing Date type fields:

[com.sun.xml.bind.v2.ClassFactory] (default task-3) No default constructor found on class java.sql.Date: java.lang.NoSuchMethodException: java.sql.Date.<init>()
 at java.base/java.lang.Class.getConstructor0(Class.java:3349)
 at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2553)
 at com.sun.xml.bind//com.sun.xml.bind.v2.ClassFactory.tryGetDeclaredConstructor(ClassFactory.java:107)
 at com.sun.xml.bind//com.sun.xml.bind.v2.ClassFactory.create0(ClassFactory.java:76)
 at com.sun.xml.bind//com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.createInstance(ClassBeanInfoImpl.java:254)
 at com.sun.xml.bind//com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.createInstance(UnmarshallingContext.java:671)
 at com.sun.xml.bind//com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:158)
 at com.sun.xml.bind//com.sun.xml.bind.v2.runtime.unmarshaller.ProxyLoader.startElement(ProxyLoader.java:30)
 at com.sun.xml.bind//com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:546)
 at com.sun.xml.bind//com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:525)
 at com.sun.xml.bind//com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:45)
 at com.sun.xml.bind//com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:216)
 at com.sun.xml.bind//com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:150)
 at com.sun.xml.bind//com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:385)
 at com.sun.xml.bind//com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:364)


The same problem also occurs with JBoss 8.1 under Java 21.

The generated Java code definitively contains the fields of type java.sql.Date, this is a standard type for the Date as seen in docs.
So, to provide marshall/unmarshall functionality for this type, the appropriate XMLAdapter has to be used in JBoss CXF(SOAP) stack. 
Please advise how and where to check for the registration of the adapter or provide troubleshooting steps for this issue?

Environment

Gen 8.6 EJB Web Services

Resolution

Support could not recreate the problem using the same JBoss and Java versions (also provided working example test model)

Advice from Gen Engineering:

  • The Gen runtime JAXB adapters are located in the runtime file vwrt.jar.

  • The "%Gen86%\Gen\classes\java11\modules" directory which should be used for JDK 11 builds (profile token LOC.JAVAEE_HOME) includes the jaxb-api-2.3.0.jar file. 

  • The JAXB annotations for the Date, Time, Timestamp and BigDecimal adapters are included in the package-info.java file created by the Build Tool script build_lm_java.scr (near the bottom). This package-info.java file compiles into the package-info.class file, which should be included in each <server_manager>.jar file for each assembled EJB Web Service.


For the test model provided, inside the assembled .ear file each <server_manager>.jar file contains the package-info.class file.
The source code package-info.java under the model directory shows:
*****
@XmlJavaTypeAdapters (
   {
       @XmlJavaTypeAdapter(value=com.ca.gen.vwrt.adapters.BigDecimalAdapter.class,type=java.math.BigDecimal.class),
       @XmlJavaTypeAdapter(value=com.ca.gen.vwrt.adapters.SqlDateAdapter.class,type=java.sql.Date.class),
       @XmlJavaTypeAdapter(value=com.ca.gen.vwrt.adapters.SqlTimeAdapter.class,type=java.sql.Time.class),
       @XmlJavaTypeAdapter(value=com.ca.gen.vwrt.adapters.SqlTimestampAdapter.class,type=java.sql.Timestamp.class)
   }
)
package datetest;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;

*****

As a test Support decided to remove the package-info.class file from the <server_manager>.jar file  inside the .ear file and then redeployed the .ear file.
Trying to use the EJB Web Service then resulted in an error and the JBoss 7.4.23 console showed the exact same error as reported.
*****
13:53:59,110 INFO  [com.sun.xml.bind.v2.ClassFactory] (default task-1) No default constructor found on class java.sql.Date: java.lang.NoSuchMethodException: java.sql.Date.<init>()
        at java.base/java.lang.Class.getConstructor0(Class.java:3349)
        at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2553)
...
*****

Therefore it appears the package-info.class file is missing from the deployment and if so that would be the root cause of the error (perhaps the Gen Build Tool is not being used for the complete application build/assemble process).

The user checked their built app-artefacts and the package-info.class was missing. After testing with freshly generated ones, with package-info.class inside, the exception was resolved.