Skip to content

updateCompany() method returns null values and affects database integrity #1

Description

@biswas2200

~Description
When invoking the updateCompany( ) method with valid input parameters, it sometimes returns null values for the company name and description fields. Additionally, the method appears to overwrite existing values in the database with null values, leading to data inconsistency.

@Override
    public CompanyDTO updateCompany(Long companyId, CompanyDTO companyDTO) {
        if (companyId == null || companyDTO == null) {
            return null;
        }
        Company existingSaveCompany = companyRepository.findById(companyId)
                .orElse(null);

        if (existingSaveCompany == null) {
            return null;
        }
        existingSaveCompany.setCompanyName(companyDTO.getCompanyName());
        existingSaveCompany.setCompanyDescription(companyDTO.getCompanyDescription());
        if (companyDTO.getJobs() != null && !companyDTO.getJobs().isEmpty()) {
            List<Job> jobs = companyDTO.getJobs().stream()
                    .map(JobServiceImplementation::mapToEntityJob)
                    .collect(Collectors.toList());
            existingSaveCompany.setJobs(jobs);
        } else {
            existingSaveCompany.getJobs().clear();
        }
        existingSaveCompany = companyRepository.save(existingSaveCompany);
        return mapToDTO(existingSaveCompany);
    }

Database Impact
The issue affects the database integrity by replacing existing company name and description values with null values.

Expected Behavior
The **updateCompany ()**method should update the company's name, description, and associated jobs in the database without replacing existing values with null.

Steps to Reproduce
Invoke the updateCompany () method with valid input parameters.
Check the database records for the updated company.
Additional Context
This issue occurs sporadically and does not have a consistent pattern. It seems to occur more frequently when updating companies with a large number of associated jobs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions