1

我目前正在尝试使用 Hibernate 部署示例 POJO Axis2 服务。为了避免在访问 hibernate.cfg.xml 时出现更多错误,我将我的服务分成了 2 个 Maven 项目。一个包含数据映射类和src/main/resources/hibernate.cfg.xml文件。

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="connection.url">jdbc:postgresql://localhost/prueba_drools</property>
    <property name="connection.username">prueba_drools</property>
    <property name="connection.password">123456</property>
    <property name="connection.driver_class">org.postgresql.Driver</property>
    <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    <property name="show_sql">true</property>
    <property name="format_sql">true</property>
    <property name="hbm2ddl.auto">update</property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>
    <property name="current_session_context_class">thread</property>

    <mapping class="local.lunacore.axis2test.model.Piloto"/>
    <mapping class="local.lunacore.axis2test.model.Robot"/>
    <mapping class="local.lunacore.axis2test.model.TipoRobot"/>
  </session-factory>
</hibernate-configuration>

另一个具有用作 Web 服务的 POJO。

package local.lunacore.axis2test;

import local.lunacore.axis2test.model.*;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;

/**
 * Hello world!
 *
 */
public class Axis2TestService
{
    public void seed()
    {
        SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        Session session = sessionFactory.getCurrentSession();
        Transaction tx = session.beginTransaction();

        TipoRobot tipoRobotMelee = new TipoRobot();
        tipoRobotMelee.setNombre("Melee (Combate cuerpo a cuerpo)");
        session.save(tipoRobotMelee);

        TipoRobot tipoRobotArtilleria = new TipoRobot();
        tipoRobotArtilleria.setNombre("Artillería");
        session.save(tipoRobotArtilleria);

        TipoRobot tipoRobotAereo = new TipoRobot();
        tipoRobotAereo.setNombre("Aéreo");
        session.save(tipoRobotAereo);

        TipoRobot tipoRobotSoporte = new TipoRobot();
        tipoRobotSoporte.setNombre("Soporte");
        session.save(tipoRobotSoporte);

        Robot robotGundamStrikeFreedom = new Robot();
        robotGundamStrikeFreedom.setNombre("ZGMF-X20A Strike Freedom Gundam");
        robotGundamStrikeFreedom.setTipoRobot(tipoRobotMelee);
        session.save(robotGundamStrikeFreedom);

        Robot robotGundamAileStrike = new Robot();
        robotGundamAileStrike.setNombre("GAT-X105+AQM/E-X01 Aile Strike Gundam");
        robotGundamAileStrike.setTipoRobot(tipoRobotAereo);
        session.save(robotGundamAileStrike);

        Piloto pilotoKiraYamato = new Piloto();
        pilotoKiraYamato.setNombre("Kira Yamato");
        pilotoKiraYamato.getRobots().add(robotGundamStrikeFreedom);
        pilotoKiraYamato.getRobots().add(robotGundamAileStrike);
        session.save(pilotoKiraYamato);
        session.saveOrUpdate(robotGundamStrikeFreedom);
        session.saveOrUpdate(robotGundamAileStrike);

        tx.commit();
    }
}

这是我的src/main/resources/META-INF/services.xml

<serviceGroup>
    <service name="Axis2TestService" targetNamespace="http://lunacore.local/axis2test" scope="application">
        <schema schemaNamespace="http://lunacore.local/types" elementFormDefaultQualified="false"/>
        <parameter
                locked="true"
                name="ServiceClass">local.lunacore.axis2test.Axis2TestService</parameter>
    </service>
</serviceGroup>

数据模型 Maven 项目的单元测试表明 Hibernate 配置正确,可以从数据库中读取/创建数据模型。当我在 WSO2 AS 上部署它时,它部署没有错误,但是在调用该seed方法时,它崩溃了,并显示以下消息:

[2012-08-29 16:45:57,605] ERROR {org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver} -  Implementing class
java.lang.IncompatibleClassChangeError: Implementing class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at org.apache.axis2.deployment.DeploymentClassLoader.findClass(DeploymentClassLoader.java:78)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at org.apache.axis2.deployment.DeploymentClassLoader.loadClass(DeploymentClassLoader.java:273)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at local.lunacore.axis2test.Axis2TestService.seed(Axis2TestService.java:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:178)
    at org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver.invokeBusinessLogic(RPCInOnlyMessageReceiver.java:66)
    at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
    at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
    at org.wso2.carbon.core.transports.CarbonServlet.doPost(CarbonServlet.java:199)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.eclipse.equinox.http.helper.FilterServletAdaptor$FilterChainImpl.doFilter(FilterServletAdaptor.java:56)
    at org.wso2.carbon.mashup.jsservices.custom.ui.CustomUIServletFilter.doFilter(CustomUIServletFilter.java:217)
    at org.eclipse.equinox.http.helper.FilterServletAdaptor.service(FilterServletAdaptor.java:37)
    at org.eclipse.equinox.http.servlet.internal.ServletRegistration.handleRequest(ServletRegistration.java:90)
    at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:111)
    at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:67)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.wso2.carbon.bridge.BridgeServlet.service(BridgeServlet.java:164)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.wso2.carbon.server.CarbonStuckThreadDetectionValve.invoke(CarbonStuckThreadDetectionValve.java:154)
    at org.wso2.carbon.server.TomcatServer$1.invoke(TomcatServer.java:254)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
    at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:396)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:356)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1534)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
[2012-08-29 16:45:57,609] ERROR {org.apache.axis2.receivers.AbstractMessageReceiver} -  org.apache.axis2.AxisFault: Implementing class

在此先感谢,山姆

4

0 回答 0