2011-06-04 1 views
2

Je crée une nouvelle instance jaxbcontext, en passant DO en tant que classe.Mon DO contient java.sql.clob comme l'un des des champs. Ce champ de clob crée un problème lors de la création d'une nouvelle instance. Donner erreur Exception survenue Lors de la capture clobcomment surmonter "java.sql.Clob est une interface, et JAXB ne peut pas gérer les interfaces" question

com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 3 counts of IllegalAnnotationExceptions 
java.sql.Clob is an interface, and JAXB can't handle interfaces. 
    this problem is related to the following location: 
     at java.sql.Clob 
     at public java.sql.Clob com.data.subscriber.SubscriberProvTransDO.getXmlString() 
     at com.data.subscriber.SubscriberProvTransDO 
The type of the getter is java.io.InputStream but that of the setter is long. They have to be the same. 
    this problem is related to the following location: 
     at public abstract java.io.InputStream java.sql.Clob.getAsciiStream() throws java.sql.SQLException 
     at java.sql.Clob 
     at public java.sql.Clob com.data.subscriber.SubscriberProvTransDO.getXmlString() 
     at com.data.subscriber.SubscriberProvTransDO 
    this problem is related to the following location: 
     at public abstract java.io.OutputStream java.sql.Clob.setAsciiStream(long) throws java.sql.SQLException 
     at java.sql.Clob 
     at public java.sql.Clob com.data.subscriber.SubscriberProvTransDO.getXmlString() 
     at com.data.subscriber.SubscriberProvTransDO 
The type of the getter is java.io.Reader but that of the setter is long. They have to be the same. 
    this problem is related to the following location: 
     at public abstract java.io.Reader java.sql.Clob.getCharacterStream() throws java.sql.SQLException 
     at java.sql.Clob 
     at public java.sql.Clob com.data.subscriber.SubscriberProvTransDO.getXmlString() 
     at com.data.subscriber.SubscriberProvTransDO 
    this problem is related to the following location: 
     at public abstract java.io.Writer java.sql.Clob.setCharacterStream(long) throws java.sql.SQLException 
     at java.sql.Clob 
     at public java.sql.Clob com.data.subscriber.SubscriberProvTransDO.getXmlString() 
     at com.data.subscriber.SubscriberProvTransDO 

    at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:66) 
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:389) 
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:236) 
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:76) 
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:55) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:618) 
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:210) 
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:368) 
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574) 
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522) 
    at com.business.system.handler.EventProcessorHandler.insertFailure(EventProcessorHandler.java:286) 
    at com.business.system.handler.EventProcessorHandler.processRequest(EventProcessorHandler.java:184) 
    at com.business.system.EventProcessorBean.onMessage(EventProcessorBean.java:51) 
    at com.ibm.ejs.container.MessageEndpointHandler.invokeMdbMethod(MessageEndpointHandler.java:1086) 
    at com.ibm.ejs.container.MessageEndpointHandler.invoke(MessageEndpointHandler.java:773) 
    at $Proxy6.onMessage(Unknown Source) 
    at com.ibm.ws.sib.api.jmsra.impl.JmsJcaEndpointInvokerImpl.invokeEndpoint(JmsJcaEndpointInvokerImpl.java:201) 
    at com.ibm.ws.sib.ra.inbound.impl.SibRaDispatcher.dispatch(SibRaDispatcher.java:768) 
    at com.ibm.ws.sib.ra.inbound.impl.SibRaSingleProcessListener$SibRaWork.run(SibRaSingleProcessListener.java:584) 
    at com.ibm.ejs.j2c.work.WorkProxy.run(WorkProxy.java:419) 
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469) 

Répondre

3

Vous pouvez utiliser un XmlAdapter pour ce cas d'utilisation. L'adaptateur XML vous permet de convertir l'objet impossible à cartographier java.sql.Clob à un objet mappable tel que String:

ClobAdapter

import java.sql.Clob; 

import javax.xml.bind.annotation.adapters.XmlAdapter; 

public class ClobAdapter extends XmlAdapter<String, Clob> { 

    @Override 
    public Clob unmarshal(String v) throws Exception { 
     // Convert String to Clob 
    } 

    @Override 
    public String marshal(Clob v) throws Exception { 
     // Convert Clob to String 
    } 

} 

Racine

Le @XmlJavaTypeAdapter doit être défini sur la propriété Clob. Cette annotation est de savoir comment vous établissez un lien dans le XmlAdapter:

import java.sql.Clob; 

import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 

public class Root { 

    private Clob clob; 

    @XmlJavaTypeAdapter(ClobAdapter.class) 
    public Clob getClob() { 
     return clob; 
    } 

    public void setClob(Clob clob) { 
     this.clob = clob; 
    } 

} 

Démo

import javax.xml.bind.JAXBContext; 

public class Demo { 

    public static void main(String[] args) throws Exception { 
     JAXBContext jc = JAXBContext.newInstance(Root.class); 
    } 
} 

Pour plus d'informations

+0

Merci Blaise, j'ai essayé cela avant mais ne m'aide pas et donne la même erreur que mentionné ci-dessus. – ABC

+0

@ABC - Pourriez-vous essayer la démonstration courte dans ma réponse et laissez-moi savoir si vous voyez une exception? –

+0

Hey, Demo fonctionne pour moi. Maintenant confus pourquoi il ne fonctionne pas pour mon projet – ABC

Questions connexes