繁体   English   中英

Hibernate对Spring-WS无响应

[英]Hibernate Unresponsive with Spring-WS

我有一个单上下文的Spring-WS应用程序(也就是说,我的项目中只有一个文件包含定义),即something-servlet.xml。 当我通过DAO调用persist时,数据库中没有创建任何条目。 我也没有抛出任何异常。

如果我遗漏了更多有助于确定问题的信息,请告诉我。 谢谢。

一些-servlet.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:sws="http://www.springframework.org/schema/web-services"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="com.abc.direct.mailserver" />
    <context:property-placeholder location="classpath:manager.properties" />

    <sws:annotation-driven />

    <sws:dynamic-wsdl id="manager" portTypeName="AbcDirect"
        locationUri="/mailerManagerService/" targetNamespace="http://ecsdfsds.com/direct/definitions">
        <sws:xsd location="/WEB-INF/mailManagerRequest.xsd" />
    </sws:dynamic-wsdl>

    <bean id="mailServerPersistenceManager"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="directMailDataSource" />
        <property name="packagesToScan" value="com.abc.direct.mailserver.dao"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
    </bean>

    <bean id="directMailDataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${database.driverClassName}" />
        <property name="url" value="${database.url}" />
        <property name="username" value="${database.username}" />
        <property name="password" value="${database.password}" />
    </bean>
</beans>

道类:

@Entity
@Table(name="virtualusertable")
public class VirtualUser {

    @Id
    @Column(name="user")
    private String user;
//  private String domain;
//  private String targetAddress;

    public VirtualUser(String username) {
        this.user = username;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }
}

@Component
public class VirtualUsers {

    @PersistenceContext
    EntityManager entityManager;

    public void save(VirtualUser user) {
        this.entityManager.persist(user);
    }

    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }
}

终点:

@Endpoint
public class MailManagerEndpoint {

    private static final String NAMESPACE_URI = "http://asfsdfs.com/direct/schemas";
    static final Namespace NAMESPACE = Namespace.getNamespace(NAMESPACE_URI);

    private MailManagerService service;
    @Autowired
    private VirtualUsers virtualUsers;

    @Autowired
    public MailManagerEndpoint(MailManagerService mailManagerService) {

        this.service = mailManagerService;
    }

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "MailManagerRequest")
    public @ResponsePayload Element handleRequest(@RequestPayload Element element) throws JDOMException, IOException {

        VirtualUser user = new VirtualUser("newuser");
        virtualUsers.save(user);

        return new Element("success");
    }
}

启动日志: http : //pastebin.com/9Z6MWRSG

交易记录: http//pastebin.com/ZFEC0EMJ

在启动日志中,我真的很好奇为什么此块会重复7次:

2014-04-25 10:34:03,634 DEBUG EntityLoader:146 - Static select for entity com.abc.direct.mailserver.dao.VirtualUser [READ]: select virtualuse0_.user as user1_0_0_ from virtualusertable virtualuse0_ where virtualuse0_.user=?
2014-04-25 10:34:03,635 DEBUG QuerySpacesImpl:177 - Adding QuerySpace : uid = <gen:0> -> org.hibernate.loader.plan.build.internal.spaces.EntityQuerySpaceImpl@e58a68d]
2014-04-25 10:34:03,635 DEBUG FetchStyleLoadPlanBuildingAssociationVisitationStrategy:94 - Building LoadPlan...
2014-04-25 10:34:03,635 DEBUG LoadQueryJoinAndFetchProcessor:111 - processing queryspace <gen:0>
2014-04-25 10:34:03,636 DEBUG LoadPlanTreePrinter:72 - LoadPlan(entity=com.abc.direct.mailserver.dao.VirtualUser)
    - Returns
       - EntityReturnImpl(entity=com.abc.direct.mailserver.dao.VirtualUser, querySpaceUid=<gen:0>, path=com.abc.direct.mailserver.dao.VirtualUser)
    - QuerySpaces
       - EntityQuerySpaceImpl(uid=<gen:0>, entity=com.abc.direct.mailserver.dao.VirtualUser)
          - SQL table alias mapping - virtualuse0_
          - alias suffix - 0_
          - suffixed key columns - {user1_0_0_}

更新:添加@Transactional和后,persist()输出:

2014-04-25 11:24:47,517 DEBUG SharedEntityManagerCreator$SharedEntityManagerInvocationHandler:253 - Creating new EntityManager for shared EntityManager invocation
2014-04-25 11:24:47,950 DEBUG AbstractSaveEventListener:130 - Generated identifier: newuser, using strategy: org.hibernate.id.Assigned
2014-04-25 11:24:48,011 DEBUG EntityManagerFactoryUtils:435 - Closing JPA EntityManager

如果要将数据插入数据库,则需要进行事务处理。 为了让Spring提供事务,您需要将<tx:annotation-driven />放置到Spring上下文文件中,并在将数据插入DB的方法上放置@Transactional注释。 这样,Spring将在方法执行开始时为您启动事务,并在方法执行结束时将其提交(如果抛出异常,则将其回滚)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM