actframework
actframework copied to clipboard
Transaction not rolled back when exception encountered
@Transactional
@PostAction("save")
public Project save(Project project) {
project.getAuthor().save(); // pass
project.save(); // exception thrown out here
return project;
}
With the above code the author is get persisted into database even the following line throw out exception.
act version: v1.8.31.0 db plugin: act-ebean database: mysql
没法重现.
测试项目: https://github.com/actframework/actframework/tree/1.8/testapps/GH1304
代码:
package actissue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity(name = "author")
public class Author {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int id;
public String name;
}
package actissue;
import javax.persistence.*;
@Entity(name = "proj")
@UniqueConstraint(columnNames = "name")
public class Project {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int id;
public String name;
}
package actissue;
import act.db.ebean.EbeanDao;
import act.db.sql.tx.Transactional;
import org.osgl.mvc.annotation.GetAction;
import org.osgl.mvc.annotation.PostAction;
import javax.inject.Inject;
public class TestBed {
@Inject
private EbeanDao<Integer, Project> projDao;
@Inject
private EbeanDao<Integer, Author> authDao;
@GetAction("/authors")
public Iterable<Author> authorCount() {
return authDao.findAll();
}
@Transactional
@PostAction
public void saveAuthorAndProject(Author author, Project project) {
authDao.save(author);
projDao.save(project);
}
}
测试脚本:
Scenario(GH1304):
description: Transaction not rolled back when exception encountered
interactions:
- description: create the first record into database
request:
post: /
json:
author:
name: author1
project:
name: p1304
- description: "send the second record into database - exception expected"
request:
post: /
json:
author:
name: author2
project:
name: p1304 # same with first batch, expect exception raised here
response:
status: 500
- description: "fetch author list - there should only one author in the list"
request:
get: /authors
response:
size: 1
测试结果:
