@Entity
public class Business {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String address;
private String industry;
// One-to-Many relationship with Employee
@OneToMany(mappedBy = "business", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<Employee> employees;
// Constructors, Getters, and Setters
}
the abstract repository:
@Repository
public interface BusinessRepository extends JpaRepository<Business, Long> {
}
and the service:
@Service
public class BusinessService {
@Autowired
private BusinessRepository businessRepository;
// Create a new business
public Business createBusiness(Business business) {
return businessRepository.save(business);
}
// Get all employees in a business
public List<Employee> getEmployeesByBusiness(Long businessId) {
Business business = businessRepository.findById(businessId)
.orElseThrow(() -> new EntityNotFoundException("Business not found"));
return business.getEmployees();
}
// Other business-related methods
}
this should look like this:
the abstract repository:
and the service: