You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Daniel Pomrehn <da...@googlemail.com> on 2010/10/18 23:13:25 UTC

Hibernate Integration

Hi!

Does anyone know a good tutorial or example of how to integrated hibernate
into an axis2 Webservice best?
The webservice should collect Information via hibernate out of a MySQL
Database. The functions of the webservice should return integer Values, not
the Database Objects.

Thank you in advance!
Best regards
Daniel

RE: Hibernate Integration

Posted by Martin Gainty <mg...@hotmail.com>.
public class Stub extends org.apache.axis.client.Stub implements org.apache.axis.sample.echo.Echo 
{
//assume this is the Hibernate call
public String doHibernate()
{
  Session s = environment.getSessionFactory().openSession();
  String in= (String) s.createQuery("select query_column from QueryTable").uniqueResult();
  String id=getId(in);
  s.delete( id ); //delete that record
  s.flush();       //flush the session 
  s.connection().commit();  //commit the transaction
  s.close();    //close handles
  return in;
}
 
//assume you have this Axis environment
   static org.apache.axis.description.OperationDesc [] _operations = new org.apache.axis.description.OperationDesc[4];
      static {
        _operations = new org.apache.axis.description.OperationDesc[4];
        _initOperationDesc1();  //init the first operation
    } 
 
//intialise the operation
 private static void _initOperationDesc1()
 {
        org.apache.axis.description.OperationDesc oper;
        oper = new org.apache.axis.description.OperationDesc();
        oper.setName("echoString");   //set the name of the operation
 
//add parameters
        oper.addParameter(new javax.xml.namespace.QName("", "in"), new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), java.lang.String.class, org.apache.axis.description.ParameterDesc.IN, false, false);
 
//declare String return type
        oper.setReturnType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
//declare the returned class
        oper.setReturnClass(java.lang.String.class);
        oper.setReturnQName(new javax.xml.namespace.QName("", "echoStringReturn"));
        oper.setStyle(org.apache.axis.enum.Style.RPC);
        oper.setUse(org.apache.axis.enum.Use.ENCODED);
        _operations[0] = oper;
 
       org.apache.axis.client.Call _call = createCall(); //see below

        _call.setOperation(_operations[0]); //set the operation for the call to point to OperationDesc
        _call.setUseSOAPAction(true);
        _call.setSOAPActionURI("");
        _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
 
//set the operationName
        _call.setOperationName(new javax.xml.namespace.QName("http://axis.apache.org/sample/echo", "echoString"));
//push the call onto the Request Headers
        setRequestHeaders(_call);
        setAttachments(_call);
        String in=doHibernate();
        java.lang.Object _resp = _call.invoke(new java.lang.Object[] {in});
    }
 
    private org.apache.axis.client.Call createCall() throws java.rmi.RemoteException {
        try {
            org.apache.axis.client.Call _call =
                    (org.apache.axis.client.Call) super.service.createCall();
   _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
            if (super.maintainSessionSet) {
                _call.setMaintainSession(super.maintainSession);
            }
            if (super.cachedUsername != null) {
                _call.setUsername(super.cachedUsername);
            }
            if (super.cachedPassword != null) {
                _call.setPassword(super.cachedPassword);
            }
            if (super.cachedEndpoint != null) {
                _call.setTargetEndpointAddress(super.cachedEndpoint);
            }
            if (super.cachedTimeout != null) {
                _call.setTimeout(super.cachedTimeout);
            }
            if (super.cachedPortName != null) {
                _call.setPortName(super.cachedPortName);
            }
            java.util.Enumeration keys = super.cachedProperties.keys();
            while (keys.hasMoreElements()) {
                java.lang.String key = (java.lang.String) keys.nextElement();
                _call.setProperty(key, super.cachedProperties.get(key));
            }
            // All the type mapping information is registered
            // when the first call is made.
            // The type mapping information is actually registered in
            // the TypeMappingRegistry of the service, which
            // is the reason why registration is only needed for the first call.
            synchronized (this) {
                if (firstCall()) {
                    // must set encoding style before registering serializers
                    _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
                    _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);
                    for (int i = 0; i < cachedSerFactories.size(); ++i) {
                        java.lang.Class cls = (java.lang.Class) cachedSerClasses.get(i);
                        javax.xml.namespace.QName qName =
                                (javax.xml.namespace.QName) cachedSerQNames.get(i);
                        java.lang.Class sf = (java.lang.Class)
                                 cachedSerFactories.get(i);
                        java.lang.Class df = (java.lang.Class)
                                 cachedDeserFactories.get(i);
                        _call.registerTypeMapping(cls, qName, sf, df, false);
                    }
                }
            }
            return _call;
        }
        catch (java.lang.Throwable _t) {
            throw new org.apache.axis.AxisFault("Failure trying to get the Call object", _t);
        }
    } //end createCall

}  //end stub

Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.



 



Date: Mon, 18 Oct 2010 23:13:25 +0200
Subject: Hibernate Integration
From: daniel.pomrehn@googlemail.com
To: java-user@axis.apache.org

Hi! 


Does anyone know a good tutorial or example of how to integrated hibernate into an axis2 Webservice best? 
The webservice should collect Information via hibernate out of a MySQL Database. The functions of the webservice should return integer Values, not the Database Objects.


Thank you in advance! 
Best regards
Daniel