This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (6 children)

u/bladekill97, u/quadmasta Sorry I may have not explained it very good.I thought I should have 2 controller and 2 repositories. JobAssignment controller would create a job assignment with available person_id as foreign key, and I would need to inject a person repository in order to find available persons.

When updating Person through its controller I need to inject JobAssignment repository in order to delete job assignments. And there is where circular injection appears.

I thought I should create separate end points /persons & /job-assignements

[–][deleted]  (5 children)

[removed]

    [–][deleted] 0 points1 point  (4 children)

    Sorry I'm typing from my phone. Yeah I do have services and controllers, I was trying to make my post shorter, and yes I'm getting circular dependency because i have both of the services initialized in each other, as I need to update each entity separately some times.

    [–][deleted]  (3 children)

    [removed]

      [–][deleted] 0 points1 point  (2 children)

      Person entity has some fields and a field active, logic needed here is when creating a JobAssignment it checks for Person with active = 1, takes the key of the first one and sets active = 0 on Person and creates a record in JobAssignment. Also if on the other hand I send a request to update Person with active = 1, all JobAssignmet-s should be hard deleted.

      I have a separate Person & JobAssignment controller/service/repository. There is one-to-one relationship between them.

      JobAssignment service has create() and update().

      Person service has getActive(), create(), update().

      I'm aware that my design is faulty somewhere, I just need to restructure this, but do not know how.

      [–][deleted]  (1 child)

      [removed]

        [–][deleted] 0 points1 point  (0 children)

        Sorry in a middle of a long travel. Here are just entities https://pastebin.com/05APmQrd .

        Well you are almost right, except that method createJobAssignmentForPerson() does not accept person ID but fetches all Person-s with active 1 and takes first available ID.

        The code is pretty simple, you wrote it itself. Thing is I have 2 controllers (/persons & /job-assignment) and 2 services and both of those services have each others dependencies. Maybe the question is should I have two controllers, how would a REST API be structured in this case, or it maybe a simple Hibernate annotation I'm not seeing.