SpringBoot2.0 hikari jpa hibernate mysql @Transactional 事务不回滚,帮解决奖励红包100元
这个是我的配置,正常运行没问题,事务就是不回滚,直接成功保存到数据库,搞了好多天,无语了,求大神帮忙解决 ,
使用 SessionFactory 写sql, 数据库是 InnoDB 没问题,之前用的是springMVC框架,连接数据库,事务回滚没问题,换成springBoog 框架,现在就不行了,事务无法回滚,求大神帮忙。
如果 成功帮助解决,留下联系方式,必有红包100元感谢
server.port=8080
server.servlet-path=/
logging.level.org.springframework=none
spring.resources.static-locations=classpath\:/
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp
server.tomcat.uri-encoding=UTF-8
#database
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://XXXXXXX:3306/XXXXX?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useOldAliasMetadataBehavior=true&zeroDateTimeBehavior=convertToNull&useSSL=true
spring.datasource.username=XXXXXXXX
spring.datasource.password=XXXX
#aop
spring.aop.auto=true
spring.aop.proxy-target-class=true
#hikari
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.data-source-properties.prepStmtCacheSqlLimit=204800
spring.datasource.hikari.minimum-idle=50
spring.datasource.hikari.maximum-pool-size=200
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.idle-timeout=600000
spring.datasource.hikari.pool-name=DatebookHikariCP
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1
#jpa
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.database=MYSQL
spring.jpa.show-sql=true
spring.servlet.multipart.max-file-size=10240Mb
spring.http.multipart.max-request-size=102400Mb
@Service
public class Dao implements IDao {
@Autowired
private SessionFactory sessionFactory;
private Session session;
private Session getSession() {
if( null == session || !session.isOpen() )
session = sessionFactory.getCurrentSession();
return session;
}
public long add(final String sql, final String[] columns, final String[] columntyles) throws SQLException {
final long[] id = new long[1];
id[0] = 0;
Session session = getSession();
Work work = new Work() {
public void execute(Connection con) throws SQLException {
PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
ps = getPsColumn(columns, columntyles, ps);
int count = ps.executeUpdate();
id[0] = getId(count, ps);
ps.close();
setSql_log(null, sql, columns, columntyles);
}
};
session.doWork(work);
return id[0];
}
public int update(final String sql, final String[] columns) throws SQLException {
SQLQuery sqlQuery = getSession().createSQLQuery(sql);
if (null != columns) {
int length = columns.length;
for (int i = 0; i < length; i++)
sqlQuery.setString(i, columns[i]);
}
return sqlQuery.executeUpdate();
}
}
@Repository
public class Of_sys_type implements IOf_sys_type {
/** 更新编辑项:提交 */
@Override
public int update(HashMap<String, String> entity) throws Exception {
HashMap<String, String> where = new HashMap<String, String>();
where.put("sys_type_id", entity.get("sys_type_id"));
return dao.update(dao.update_Sql(entity, where, "of_sys_type"));
}
}
/** 执行更新 编辑菜单(1、2、3级) **/
@Transactional(rollbackFor= {RuntimeException.class,Exception.class})
public int typeOneExeEdit(Form form) throws Exception {
id = of_sys_type.update(form.getEntity());
if( 0 < id ) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动事务处理
throw new RuntimeException();
}
return id;
}