关于no transaction is in progress错误的解决方法

在使用spring +jpa开发中

结构dao+service+action三层

dao继承basedao

basedao中写了方法

 public T merge(T entity) {
  T returnObj = this.getJpaTemplate().merge(entity);
  this.getJpaTemplate().flush();
  return returnObj;
 }


在service中自动注入dao

 @Autowired
 private CityDao cityDao

 @Transactional  public City merge (City city){
  if (city == null)
   return city;
  return cityDao.merge(city);
 }

如果不写@Transactional就报错,no transaction is in progress

写上就正常,原因调查中。。。

你可能感兴趣的:(DAO,spring,service,jpa,merge,Autowired)