I want to create a spouse tab in my Employee entity and it should display the data related to the employee. I usea Monolith apllication with sql database and vue.
<router-link
:to="{ name: 'THrpEmployeeTabEdit2', params: { tHrpEmpSpouseId: $route.params.tHrpEmployeeId } }"
class="nav-link tab-bar"
>Spouse</router-link>
I notice what this code do is passing a route parameter tHrpEmpSpouseId which is equal to $route.params.tHrpEmployeeId which is Id from t-hrp-emp-spouses table and id from t-hrp-employee table and it has mismatch of data since the both of the id can be different.
Here is employee query service: package com.sains.hrpay.service;
import com.sains.hrpay.domain.*; // for static metamodels
import com.sains.hrpay.domain.THrpEmployee;
import com.sains.hrpay.repository.THrpEmployeeRepository;
import com.sains.hrpay.service.criteria.THrpEmployeeCriteria;
import java.util.List;
import javax.persistence.criteria.JoinType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tech.jhipster.service.QueryService;
/**
* Service for executing complex queries for {@link THrpEmployee} entities in the database.
* The main input is a {@link THrpEmployeeCriteria} which gets converted to {@link Specification},
* in a way that all the filters must apply.
* It returns a {@link List} of {@link THrpEmployee} or a {@link Page} of {@link THrpEmployee} which fulfills the criteria.
*/
@Service
@Transactional(readOnly = true)
public class THrpEmployeeQueryService extends QueryService<THrpEmployee> {
private final Logger log = LoggerFactory.getLogger(THrpEmployeeQueryService.class);
private final THrpEmployeeRepository tHrpEmployeeRepository;
public THrpEmployeeQueryService(THrpEmployeeRepository tHrpEmployeeRepository) {
this.tHrpEmployeeRepository = tHrpEmployeeRepository;
}
/**
* Return a {@link List} of {@link THrpEmployee} which matches the criteria from the database.
* @param criteria The object which holds all the filters, which the entities should match.
* @return the matching entities.
*/
@Transactional(readOnly = true)
public List<THrpEmployee> findByCriteria(THrpEmployeeCriteria criteria) {
log.debug("find by criteria : {}", criteria);
final Specification<THrpEmployee> specification = createSpecification(criteria);
return tHrpEmployeeRepository.findAll(specification);
}
/**
* Return a {@link Page} of {@link THrpEmployee} which matches the criteria from the database.
* @param criteria The object which holds all the filters, which the entities should match.
* @param page The page, which should be returned.
* @return the matching entities.
*/
@Transactional(readOnly = true)
public Page<THrpEmployee> findByCriteria(THrpEmployeeCriteria criteria, Pageable page) {
log.debug("find by criteria : {}, page: {}", criteria, page);
final Specification<THrpEmployee> specification = createSpecification(criteria);
return tHrpEmployeeRepository.findAll(specification, page);
}
/**
* Return the number of matching entities in the database.
* @param criteria The object which holds all the filters, which the entities should match.
* @return the number of matching entities.
*/
@Transactional(readOnly = true)
public long countByCriteria(THrpEmployeeCriteria criteria) {
log.debug("count by criteria : {}", criteria);
final Specification<THrpEmployee> specification = createSpecification(criteria);
return tHrpEmployeeRepository.count(specification);
}
/**
* Function to convert {@link THrpEmployeeCriteria} to a {@link Specification}
* @param criteria The object which holds all the filters, which the entities should match.
* @return the matching {@link Specification} of the entity.
*/
protected Specification<THrpEmployee> createSpecification(THrpEmployeeCriteria criteria) {
Specification<THrpEmployee> specification = Specification.where(null);
if (criteria != null) {
if (criteria.getId() != null) {
specification = specification.and(buildRangeSpecification(criteria.getId(), THrpEmployee_.id));
}
if (criteria.getStaffFileNo() != null) {
specification = specification.and(buildStringSpecification(criteria.getStaffFileNo(), THrpEmployee_.staffFileNo));
}
if (criteria.getStaffFileNumber() != null) {
specification = specification.and(buildStringSpecification(criteria.getStaffFileNumber(), THrpEmployee_.staffFileNumber));
}
if (criteria.getStaffName() != null) {
specification = specification.and(buildStringSpecification(criteria.getStaffName(), THrpEmployee_.staffName));
}
if (criteria.getOic() != null) {
specification = specification.and(buildStringSpecification(criteria.getOic(), THrpEmployee_.oic));
}
if (criteria.getNewic() != null) {
specification = specification.and(buildStringSpecification(criteria.getNewic(), THrpEmployee_.newic));
}
if (criteria.getIdType() != null) {
specification = specification.and(buildSpecification(criteria.getIdType(), THrpEmployee_.idType));
}
if (criteria.getStaffNameAlias() != null) {
specification = specification.and(buildStringSpecification(criteria.getStaffNameAlias(), THrpEmployee_.staffNameAlias));
}
if (criteria.getNameInitial() != null) {
specification = specification.and(buildStringSpecification(criteria.getNameInitial(), THrpEmployee_.nameInitial));
}
if (criteria.getContactNo() != null) {
specification = specification.and(buildStringSpecification(criteria.getContactNo(), THrpEmployee_.contactNo));
}
if (criteria.getMobileNo() != null) {
specification = specification.and(buildStringSpecification(criteria.getMobileNo(), THrpEmployee_.mobileNo));
}
if (criteria.getDob() != null) {
specification = specification.and(buildRangeSpecification(criteria.getDob(), THrpEmployee_.dob));
}
if (criteria.getGender() != null) {
specification = specification.and(buildSpecification(criteria.getGender(), THrpEmployee_.gender));
}
if (criteria.getReligion() != null) {
specification = specification.and(buildStringSpecification(criteria.getReligion(), THrpEmployee_.religion));
}
if (criteria.getRace() != null) {
specification = specification.and(buildStringSpecification(criteria.getRace(), THrpEmployee_.race));
}
if (criteria.getHomeAddress1() != null) {
specification = specification.and(buildStringSpecification(criteria.getHomeAddress1(), THrpEmployee_.homeAddress1));
}
if (criteria.getHomeAddress2() != null) {
specification = specification.and(buildStringSpecification(criteria.getHomeAddress2(), THrpEmployee_.homeAddress2));
}
if (criteria.getHomeAddress3() != null) {
specification = specification.and(buildStringSpecification(criteria.getHomeAddress3(), THrpEmployee_.homeAddress3));
}
if (criteria.getHomeAddressCountry() != null) {
specification =
specification.and(buildStringSpecification(criteria.getHomeAddressCountry(), THrpEmployee_.homeAddressCountry));
}
if (criteria.getHomeAddressState() != null) {
specification = specification.and(buildStringSpecification(criteria.getHomeAddressState(), THrpEmployee_.homeAddressState));
}
if (criteria.getHomeAddressCity() != null) {
specification = specification.and(buildStringSpecification(criteria.getHomeAddressCity(), THrpEmployee_.homeAddressCity));
}
if (criteria.getHomeAddressPostcode() != null) {
specification =
specification.and(buildStringSpecification(criteria.getHomeAddressPostcode(), THrpEmployee_.homeAddressPostcode));
}
if (criteria.getCorrespondAddress1() != null) {
specification =
specification.and(buildStringSpecification(criteria.getCorrespondAddress1(), THrpEmployee_.correspondAddress1));
}
if (criteria.getCorrespondAddress2() != null) {
specification =
specification.and(buildStringSpecification(criteria.getCorrespondAddress2(), THrpEmployee_.correspondAddress2));
}
if (criteria.getCorrespondAddress3() != null) {
specification =
specification.and(buildStringSpecification(criteria.getCorrespondAddress3(), THrpEmployee_.correspondAddress3));
}
if (criteria.getCorrespondAddressCountry() != null) {
specification =
specification.and(
buildStringSpecification(criteria.getCorrespondAddressCountry(), THrpEmployee_.correspondAddressCountry)
);
}
if (criteria.getCorrespondAddressState() != null) {
specification =
specification.and(buildStringSpecification(criteria.getCorrespondAddressState(), THrpEmployee_.correspondAddressState));
}
if (criteria.getCorrespondAddressCity() != null) {
specification =
specification.and(buildStringSpecification(criteria.getCorrespondAddressCity(), THrpEmployee_.correspondAddressCity));
}
if (criteria.getCorrespondAddressPostcode() != null) {
specification =
specification.and(
buildStringSpecification(criteria.getCorrespondAddressPostcode(), THrpEmployee_.correspondAddressPostcode)
);
}
if (criteria.getNationality() != null) {
specification = specification.and(buildStringSpecification(criteria.getNationality(), THrpEmployee_.nationality));
}
if (criteria.getDivision() != null) {
specification = specification.and(buildStringSpecification(criteria.getDivision(), THrpEmployee_.division));
}
if (criteria.getMarriedStatus() != null) {
specification = specification.and(buildStringSpecification(criteria.getMarriedStatus(), THrpEmployee_.marriedStatus));
}
if (criteria.getPlaceBirth() != null) {
specification = specification.and(buildStringSpecification(criteria.getPlaceBirth(), THrpEmployee_.placeBirth));
}
if (criteria.getDisability() != null) {
specification = specification.and(buildStringSpecification(criteria.getDisability(), THrpEmployee_.disability));
}
if (criteria.getRecstatus() != null) {
specification = specification.and(buildSpecification(criteria.getRecstatus(), THrpEmployee_.recstatus));
}
if (criteria.getStaffStatus() != null) {
specification = specification.and(buildStringSpecification(criteria.getStaffStatus(), THrpEmployee_.staffStatus));
}
if (criteria.getResidentialStatus() != null) {
specification =
specification.and(buildStringSpecification(criteria.getResidentialStatus(), THrpEmployee_.residentialStatus));
}
if (criteria.getTopOrgid() != null) {
specification = specification.and(buildStringSpecification(criteria.getTopOrgid(), THrpEmployee_.topOrgid));
}
if (criteria.getEnteredBy() != null) {
specification = specification.and(buildStringSpecification(criteria.getEnteredBy(), THrpEmployee_.enteredBy));
}
if (criteria.getEnteredDt() != null) {
specification = specification.and(buildRangeSpecification(criteria.getEnteredDt(), THrpEmployee_.enteredDt));
}
if (criteria.getModifiedBy() != null) {
specification = specification.and(buildStringSpecification(criteria.getModifiedBy(), THrpEmployee_.modifiedBy));
}
if (criteria.getModifiedDt() != null) {
specification = specification.and(buildRangeSpecification(criteria.getModifiedDt(), THrpEmployee_.modifiedDt));
}
if (criteria.getConfirmedBy() != null) {
specification = specification.and(buildStringSpecification(criteria.getConfirmedBy(), THrpEmployee_.confirmedBy));
}
if (criteria.getConfirmedDt() != null) {
specification = specification.and(buildRangeSpecification(criteria.getConfirmedDt(), THrpEmployee_.confirmedDt));
}
if (criteria.getTHrpEmpSpouseId() != null) {
specification =
specification.and(
buildSpecification(
criteria.getTHrpEmpSpouseId(),
root -> root.join(THrpEmployee_.tHrpEmpSpouses, JoinType.LEFT).get(THrpEmpSpouse_.id)
)
);
}
if (criteria.getTHrpEmpChildId() != null) {
specification =
specification.and(
buildSpecification(
criteria.getTHrpEmpChildId(),
root -> root.join(THrpEmployee_.tHrpEmpChildren, JoinType.LEFT).get(THrpEmpChild_.id)
)
);
}
if (criteria.getEmpDeductionId() != null) {
specification =
specification.and(
buildSpecification(
criteria.getEmpDeductionId(),
root -> root.join(THrpEmployee_.empDeduction, JoinType.LEFT).get(THrpEmpDeduction_.id)
)
);
}
}
return specification;
}
}
and spose query service:
package com.sains.hrpay.service;
import com.sains.hrpay.domain.*; // for static metamodels
import com.sains.hrpay.domain.THrpEmpSpouse;
import com.sains.hrpay.repository.THrpEmpSpouseRepository;
import com.sains.hrpay.service.criteria.THrpEmpSpouseCriteria;
import java.util.List;
import javax.persistence.criteria.JoinType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tech.jhipster.service.QueryService;
/**
* Service for executing complex queries for {@link THrpEmpSpouse} entities in the database.
* The main input is a {@link THrpEmpSpouseCriteria} which gets converted to {@link Specification},
* in a way that all the filters must apply.
* It returns a {@link List} of {@link THrpEmpSpouse} or a {@link Page} of {@link THrpEmpSpouse} which fulfills the criteria.
*/
@Service
@Transactional(readOnly = true)
public class THrpEmpSpouseQueryService extends QueryService<THrpEmpSpouse> {
private final Logger log = LoggerFactory.getLogger(THrpEmpSpouseQueryService.class);
private final THrpEmpSpouseRepository tHrpEmpSpouseRepository;
public THrpEmpSpouseQueryService(THrpEmpSpouseRepository tHrpEmpSpouseRepository) {
this.tHrpEmpSpouseRepository = tHrpEmpSpouseRepository;
}
/**
* Return a {@link List} of {@link THrpEmpSpouse} which matches the criteria from the database.
* @param criteria The object which holds all the filters, which the entities should match.
* @return the matching entities.
*/
@Transactional(readOnly = true)
public List<THrpEmpSpouse> findByCriteria(THrpEmpSpouseCriteria criteria) {
log.debug("find by criteria : {}", criteria);
final Specification<THrpEmpSpouse> specification = createSpecification(criteria);
return tHrpEmpSpouseRepository.findAll(specification);
}
/**
* Return a {@link Page} of {@link THrpEmpSpouse} which matches the criteria from the database.
* @param criteria The object which holds all the filters, which the entities should match.
* @param page The page, which should be returned.
* @return the matching entities.
*/
@Transactional(readOnly = true)
public Page<THrpEmpSpouse> findByCriteria(THrpEmpSpouseCriteria criteria, Pageable page) {
log.debug("find by criteria : {}, page: {}", criteria, page);
final Specification<THrpEmpSpouse> specification = createSpecification(criteria);
return tHrpEmpSpouseRepository.findAll(specification, page);
}
/**
* Return the number of matching entities in the database.
* @param criteria The object which holds all the filters, which the entities should match.
* @return the number of matching entities.
*/
@Transactional(readOnly = true)
public long countByCriteria(THrpEmpSpouseCriteria criteria) {
log.debug("count by criteria : {}", criteria);
final Specification<THrpEmpSpouse> specification = createSpecification(criteria);
return tHrpEmpSpouseRepository.count(specification);
}
/**
* Function to convert {@link THrpEmpSpouseCriteria} to a {@link Specification}
* @param criteria The object which holds all the filters, which the entities should match.
* @return the matching {@link Specification} of the entity.
*/
protected Specification<THrpEmpSpouse> createSpecification(THrpEmpSpouseCriteria criteria) {
Specification<THrpEmpSpouse> specification = Specification.where(null);
if (criteria != null) {
if (criteria.getId() != null) {
specification = specification.and(buildRangeSpecification(criteria.getId(), THrpEmpSpouse_.id));
}
if (criteria.getSpouseName() != null) {
specification = specification.and(buildStringSpecification(criteria.getSpouseName(), THrpEmpSpouse_.spouseName));
}
if (criteria.getSpouseDob() != null) {
specification = specification.and(buildRangeSpecification(criteria.getSpouseDob(), THrpEmpSpouse_.spouseDob));
}
if (criteria.getOldIc() != null) {
specification = specification.and(buildStringSpecification(criteria.getOldIc(), THrpEmpSpouse_.oldIc));
}
if (criteria.getNewIc() != null) {
specification = specification.and(buildStringSpecification(criteria.getNewIc(), THrpEmpSpouse_.newIc));
}
if (criteria.getIdType() != null) {
specification = specification.and(buildSpecification(criteria.getIdType(), THrpEmpSpouse_.idType));
}
if (criteria.getSpousestatus() != null) {
specification = specification.and(buildStringSpecification(criteria.getSpousestatus(), THrpEmpSpouse_.spousestatus));
}
if (criteria.getWorking() != null) {
specification = specification.and(buildStringSpecification(criteria.getWorking(), THrpEmpSpouse_.working));
}
if (criteria.getOccupation() != null) {
specification = specification.and(buildStringSpecification(criteria.getOccupation(), THrpEmpSpouse_.occupation));
}
if (criteria.getCompany() != null) {
specification = specification.and(buildStringSpecification(criteria.getCompany(), THrpEmpSpouse_.company));
}
if (criteria.getCompanyAddr() != null) {
specification = specification.and(buildStringSpecification(criteria.getCompanyAddr(), THrpEmpSpouse_.companyAddr));
}
if (criteria.getNationality() != null) {
specification = specification.and(buildStringSpecification(criteria.getNationality(), THrpEmpSpouse_.nationality));
}
if (criteria.getIncometaxNo() != null) {
specification = specification.and(buildStringSpecification(criteria.getIncometaxNo(), THrpEmpSpouse_.incometaxNo));
}
if (criteria.getJointTax() != null) {
specification = specification.and(buildStringSpecification(criteria.getJointTax(), THrpEmpSpouse_.jointTax));
}
if (criteria.getTaxBranch() != null) {
specification = specification.and(buildStringSpecification(criteria.getTaxBranch(), THrpEmpSpouse_.taxBranch));
}
if (criteria.getMarriedDate() != null) {
specification = specification.and(buildRangeSpecification(criteria.getMarriedDate(), THrpEmpSpouse_.marriedDate));
}
if (criteria.getDivorcedDate() != null) {
specification = specification.and(buildRangeSpecification(criteria.getDivorcedDate(), THrpEmpSpouse_.divorcedDate));
}
if (criteria.getDeceasedDate() != null) {
specification = specification.and(buildRangeSpecification(criteria.getDeceasedDate(), THrpEmpSpouse_.deceasedDate));
}
if (criteria.getContactNo() != null) {
specification = specification.and(buildStringSpecification(criteria.getContactNo(), THrpEmpSpouse_.contactNo));
}
if (criteria.getMobileNo() != null) {
specification = specification.and(buildStringSpecification(criteria.getMobileNo(), THrpEmpSpouse_.mobileNo));
}
if (criteria.getProportionateMthYear() != null) {
specification =
specification.and(buildStringSpecification(criteria.getProportionateMthYear(), THrpEmpSpouse_.proportionateMthYear));
}
if (criteria.getMedicalEntitlement() != null) {
specification =
specification.and(buildRangeSpecification(criteria.getMedicalEntitlement(), THrpEmpSpouse_.medicalEntitlement));
}
if (criteria.getMedicalBalance() != null) {
specification = specification.and(buildRangeSpecification(criteria.getMedicalBalance(), THrpEmpSpouse_.medicalBalance));
}
if (criteria.getTotalMedicalClaim() != null) {
specification =
specification.and(buildRangeSpecification(criteria.getTotalMedicalClaim(), THrpEmpSpouse_.totalMedicalClaim));
}
if (criteria.getRecstatus() != null) {
specification = specification.and(buildSpecification(criteria.getRecstatus(), THrpEmpSpouse_.recstatus));
}
if (criteria.getEnteredBy() != null) {
specification = specification.and(buildStringSpecification(criteria.getEnteredBy(), THrpEmpSpouse_.enteredBy));
}
if (criteria.getEnteredDt() != null) {
specification = specification.and(buildRangeSpecification(criteria.getEnteredDt(), THrpEmpSpouse_.enteredDt));
}
if (criteria.getModifiedBy() != null) {
specification = specification.and(buildStringSpecification(criteria.getModifiedBy(), THrpEmpSpouse_.modifiedBy));
}
if (criteria.getModifiedDt() != null) {
specification = specification.and(buildRangeSpecification(criteria.getModifiedDt(), THrpEmpSpouse_.modifiedDt));
}
if (criteria.getEmployeeIdId() != null) {
specification =
specification.and(
buildSpecification(
criteria.getEmployeeIdId(),
root -> root.join(THrpEmpSpouse_.employeeId, JoinType.LEFT).get(THrpEmployee_.id)
)
);
}
}
return specification;
}
}
So I create a relationship one to many that is associate with t-hrp-employee table which follows the value of employee id. How can I use it?
<changeSet id="20240222064812-1-add-relationships" author="jhipster">
<addColumn tableName="t_hrp_emp_child">
<column name="employee_id_id" type="bigint" />
</addColumn>
</changeSet>
<changeSet id="20240222063658-relationship-foreign-keys" author="jhipster">
<addForeignKeyConstraint baseColumnNames="employee_id_id"
baseTableName="t_hrp_emp_spouse"
constraintName="fk_t_hrp_emp_spouse__employee_id_id"
referencedColumnNames="id"
referencedTableName="t_hrp_employee"/>
</changeSet>