Bahor @ ishorali annotatsiya foydalanish

Agar men cheklovsiz tekshirish usulida @Transactional annotatsiya qo'ymasam, audit jurnali saqlanmaydi .Ammo qat'iylikda davom ettirish uslubi Servis allready this annotation. Nima uchun bu izohni qo'yish kerak.

  @RequestMapping(value = "/lemf", method = RequestMethod.POST, headers = "Accept=application/json")
    public
    @ResponseBody
    Lemf create(HttpServletResponse response, @RequestBody Lemf lemf) {
        try {
            Lemf l = limsService.findLemfByName(lemf.getName());
            if (l == null) {
                     lemf=   limsService.addLemf(lemf);
                    limsService.audit("User action",getRequestInfo(),"New lemf created.");
                     return  lemf;
            }
            sendError(response, "Lemf Allready exist.");


        } catch (ProviderException e) {
            sendError(response, e);
        }
        return null;
    }


public class PersistenceServiceImpl implements PersistenceService {

   @Transactional(readOnly = false)
    public  T persist(T obj) {
        if (obj.getSystemId() != AbstractPersistable.UNSAVED_ID_VALUE) {
            log.info("Updating... :" + obj);
            T merged = em.merge(obj);
            return merged;
        } else {
            em.persist(obj);
            return obj;
        }
    }

}


public class LimsServiceImpl implements LimsService {
  @Override
    public Lemf addLemf(Lemf lemf) throws ProviderException {
        return  persistenceService.persist(lemf);
    }

    @Transactional
    public void  audit(String type,Pair  pair,String log)  {
         auditService. audit("User action", pair, "New lemf created.");
    }

}
3

1 javoblar

Spring Reference chapter 10.5.6. Using @Transactional

Bu haqda juda aniq:

Maslahat

     

Bahor sizning izohingiz interfeyslaridan farqli o'laroq, faqat @Transactional annotatsiyasi bilan aniq sinflarni (va aniq sinflar metodlarini) izohlashingizni tavsiya qiladi. Siz, albatta, @Transactional izohini interfeysga (yoki interfeys usuliga) joylashtirasiz, ammo bu interfeysga asoslangan proksi-serverlardan foydalanayotgan bo'lsangiz, bu faqat siz kutmoqdasiz. Java annotatsiyasi interfeysdan meros bo'lib o'tmaganligi, agar sinfga asoslangan proksi-server (proksi-maqsad-sinf = "haqiqiy") yoki to'quv-asosidagi aspekt (mode = "aspectj") dan foydalansangiz, tranzaksiya sozlamalari proksi va to'quv infratuzilmasi tomonidan e'tirof etilmaydi va ob'ekt shubhasiz yomonlashishi mumkin bo'lgan tranzaktsion proksi-serverga o'ralmaydi.

1
qo'shib qo'ydi