Buggy code:
@ Service public class UserOrdinaturDetailServiceImpl implements UserOrdinaturDetailService { @ Autowired private UserOrdinaturDetailDao userOrdinaturDetailDao ; @ Autowired private DocumentInfoService documentInfoService ; @ Autowired private DocumentInfoDao documentInfoDao ; @ Autowired private BaseService baseService ; @ Autowired private UserRegistrationInformationService userRegistrationInformationService ; @ Override @ Transactional ( readOnly = false , propagation = Propagation . REQUIRES_NEW , rollbackFor = Exception . class ) public UserOrdinaturDetail saveOrdinaturDetails ( final UserOrdinaturDetail userOrdinaturDetail ) { } @ Override @ Transactional ( readOnly = true , propagation = Propagation . REQUIRES_NEW ) public UserOrdinaturDetailDto getOrdinatorDtoForUser ( final Long userId ) { } @ Override @ Transactional ( readOnly = false , propagation = Propagation . REQUIRES_NEW , rollbackFor = Exception . class ) public UserOrdinaturDetail saveOrdinaturdetails ( final UserOrdinaturDetailDto dto , final GdeUser user ) { try { UserOrdinaturDetail userOrdinaturDetail ; <START_BUG> if ( ( dto != null ) && ( ( dto . getObjId ( ) ) == 0 ) ) { <END_BUG> userOrdinaturDetail = userOrdinaturDetailDao . getUserOrdinaturDetail ( user . getId ( ) ) ; if ( userOrdinaturDetail == null ) { userOrdinaturDetail = new UserOrdinaturDetail ( ) ; userOrdinaturDetail . setId ( 0 ) ; userOrdinaturDetail . setUser ( user ) ; } } else { userOrdinaturDetail = new UserOrdinaturDetail ( ) ; userOrdinaturDetail . setUser ( user ) ; } userOrdinaturDetail . populateDetailFromDto ( dto , user ) ; if ( ( dto . getObjId ( ) ) == 0 ) { UserRegistrationInformation uri = userRegistrationInformationService . getUserRegistrationInformation ( user . getId ( ) ) ; if ( ( ( ( uri . getCertificateType ( ) ) == ( CertificationTypeEnum . ORDINATUR ) ) && ( ! ( GDEStringUtils . isNullOrEmpty ( dto . getCertificateOrdinatur ( ) . getFileName ( ) ) ) ) ) && ( ( ( dto . getCertificateOrdinatur ( ) . getFile ( ) ) == null ) || ( dto . getCertificateOrdinatur ( ) . getFile ( ) . isEmpty ( ) ) ) ) { DocumentDto docDto = fetchDefaultOrdinaturDoc ( user ) ; docDto . setDocCategory ( ORDINATUR ) ; dto . setCertificateOrdinatur ( docDto ) ; } } userOrdinaturDetail = userOrdinaturDetailDao . saveOrMerge ( userOrdinaturDetail ) ; dto . getCertificateOrdinatur ( ) . setEntityId ( userOrdinaturDetail . getId ( ) ) ; dto . getCertificateAcademicRank ( ) . setEntityId ( userOrdinaturDetail . getId ( ) ) ; List < DocumentDto > documentDtoList = new ArrayList < DocumentDto > ( ) ; Collection < DocumentInfo > documentInfoList = new ArrayList < DocumentInfo > ( ) ; documentDtoList . add ( dto . getCertificateAcademicRank ( ) ) ; if ( ( ( dto . getOrdinaturFlag ( ) ) == null ) || ( ( GDEStringUtils . isNullOrEmpty ( dto . getCertificateOrdinatur ( ) . getFileName ( ) ) ) && ( ( ( dto . getCertificateOrdinatur ( ) . getFile ( ) ) == null ) || ( dto . getCertificateOrdinatur ( ) . getFile ( ) . isEmpty ( ) ) ) ) ) { DocumentInfo docInfo = fetchOrdinaturDoc ( user ) ; if ( docInfo != null ) { documentInfoService . deleteDocument ( docInfo ) ; } } else { documentDtoList . add ( dto . getCertificateOrdinatur ( ) ) ; } documentInfoList = documentInfoService . saveDocumentInfo ( documentDtoList , user , userOrdinaturDetail , false ) ; if ( ( documentInfoList != null ) && ( ( documentInfoList . size ( ) ) > 0 ) ) { for ( DocumentInfo docInfo : documentInfoList ) { if ( ( docInfo . getCategoryName ( ) ) == ( DocCategoryEnum . ORDINATUR ) ) { dto . getCertificateOrdinatur ( ) . setDocId ( docInfo . getId ( ) ) ; } if ( ( docInfo . getCategoryName ( ) ) == ( DocCategoryEnum . ACADEMIC ) ) { dto . getCertificateAcademicRank ( ) . setDocId ( docInfo . getId ( ) ) ; } } } return userOrdinaturDetail ; } catch ( Exception e ) { throw new GDEException ( e ) ; } } public DocumentDto fetchDefaultOrdinaturDoc ( final GdeUser user ) { } public DocumentInfo fetchOrdinaturDoc ( final GdeUser user ) { } }

Fix:
if ( ( ( dto != null ) && ( ( dto . getObjId ( ) ) != null ) ) && ( ( dto . getObjId ( ) ) == 0 ) ) {