小编Jam*_*ENL的帖子

为什么在使用SpringJUnit4ClassRunner/MySQL/Spring/Hibernate时事务没有回滚

我正在进行单元测试,我希望所有提交给MySQL数据库的数据都将被回滚......但事实并非如此.即使我的日志显示正在发生回滚,也会提交数据.我已经和它摔跤了几天,所以我的设置已经改变了很多,这是我目前的设置.

LoginDAOTest.java:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:web/WEB-INF/applicationContext-test.xml", "file:web/WEB-INF/dispatcher-servlet-test.xml"})
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
public class UserServiceTest {

  private UserService userService;

  @Test
  public void should_return_true_when_user_is_logged_in ()
          throws Exception
  {
    String[] usernames = {"a","b","c","d"};

    for (String username : usernames)
    {
      userService.logUserIn(username);
      assertThat(userService.isUserLoggedIn(username), is(equalTo(true)));
    }
  }
Run Code Online (Sandbox Code Playgroud)

ApplicationContext的-Text.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:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
          <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
          <property name="url" value="jdbc:mysql://localhost:3306/******"/>
          <property name="username" value="*****"/>
          <property name="password" value="*****"/>
  </bean>

  <tx:annotation-driven transaction-manager="transactionManager"/>

  <bean id="userService" class="Service.UserService">
    <property …
Run Code Online (Sandbox Code Playgroud)

mysql hibernate spring-mvc rollback junit4

4
推荐指数
2
解决办法
1万
查看次数

Hibernate 未映射

我使用 spring3 和 hibernate4 创建了一个项目。但它无法运行。下面提供了代码和根本原因。

@Entity
@Table(name = "Songs")
public class Song implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    Integer id;
    @Column(name = "Name", length = 100, nullable = false)
    String name;
    @Column(name = "Category", length = 100, nullable = true)
    String category;
    @Column(name = "Singer", length = 100, nullable = true)
    String singer;
    @Column(name = "Author", length = 100, nullable = true)
    String author;
//getter & setter
Run Code Online (Sandbox Code Playgroud)

我有 DAO

@Repository("musicDao")
public class MusicDaoImpl implements MusicDao { …
Run Code Online (Sandbox Code Playgroud)

java mysql spring hibernate

4
推荐指数
1
解决办法
6683
查看次数

Spring Web服务动态wsdl不为schema元素生成消息

我有以下架构:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:m="http://ws.mypackage.com" 
xmlns:xmime="http://www.w3.org/2005/05/xmlmime" elementFormDefault="qualified"
targetNamespace="http://ws.mypackage.com" 
attributeFormDefault="unqualified"> 

    <xs:element name="downloadMessageRequestSaaj">
        <xs:complexType/>
    </xs:element>

    <xs:element name="downloadMessageRequest">
        <xs:complexType/>
    </xs:element>   

    <xs:element name="downloadMessageResponseSaaj" type="m:downloadResponseSaajType" />

    <xs:complexType name="downloadResponseSaajType">
            <xs:sequence>
                <xs:element name="requestName" type="xs:string"/>
                <xs:element name="payLoad">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="messagePayLoad" type="xs:base64Binary" xmime:expectedContentTypes="multipart/related"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
     </xs:complexType>

    <xs:element name="downloadMessageResponse" type="m:downloadResponseType" />

    <xs:complexType name="downloadResponseType">
            <xs:sequence>
                <xs:element name="requestName" type="xs:string"/>
                <xs:element name="payLoad">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="messagePayLoad" type="xs:base64Binary" xmime:expectedContentTypes="multipart/related"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
     </xs:complexType>


     <xs:element name="localDTMRequest">
        <xs:complexType/>
    </xs:element>

    <xs:element name="localDTMResponse">
        <xs:complexType>        
            <xs:sequence>
                <xs:element name="localDTM" type="xs:dateTime"/>
            </xs:sequence>          
        </xs:complexType>
    </xs:element>    

</xs:schema> …
Run Code Online (Sandbox Code Playgroud)

java spring soap wsdl spring-mvc

3
推荐指数
1
解决办法
3427
查看次数

Json Schema - 如何使任意两个或多个属性成为必需

我有这个父架构:

{
    "definitions": {
        "parcel": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "string"
                },
                "accountNumber": {
                    "type": "string"
                },
                "parcelNumber": {
                    "type": "string"
                },
                "propertyType": {
                    "type": "string"
                },
                "address": {
                    "$ref": "address.json#/definitions/address"
                },
                "coordinates": {
                    "$ref": "coordinates.json#/definitions/coordinates"
                }
            },
            "required": ["accountNumber", "parcelNumber"]
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

以下是引用的子模式:

{
    "definitions": {
        "address": {
            "type": "object",
            "properties": {
                "addressString": {
                    "type": "string",
                    "addressType": {
                        "enum": ["residential", "business"]
                    }
                },
                "required": ["addressString"]
            }
        }
    }
}

    {
    "definitions": {
        "coordinates": {
            "type": …
Run Code Online (Sandbox Code Playgroud)

json jsonschema

3
推荐指数
1
解决办法
8106
查看次数

Haskell函数调用中的括号

我在努力记住在调用Haskell函数时如何使用括号.我来自C风格的背景,我习惯于f(comma, separated, args)调用函数的语法.显然这与(在Haskell中)相同,((((f) comma) separated) args)但这只是令人困惑.

为什么我需要所有这些括号?

haskell function function-call

3
推荐指数
1
解决办法
1814
查看次数

使用Spring 3进行基于注释的事务管理和对象映射的最小Hibernate 4 XML配置?

假设我已经有了一个有效的Spring项目,那么使用Spring 3 XML配置在Hibernate 4中添加的最小配置量是多少?我想使用基于注释的事务管理,并使用注释来映射我的对象.

注意:这是一个自我回答问答风格的问题,旨在为常见问题提供规范的答案.我打算随着时间的推移扩展这个问题,以便与Hibernate保持同步.

java spring hibernate jpa

1
推荐指数
1
解决办法
2366
查看次数