Official Architecture -> Meta

Asked

Viewed 42 times

1

The question I have is totally architectural. I will expose a case just below to further illustrate the doubt that I am tapping directly into my system.

I have a feature that aims to register an employee. Such employee is composed of basic fields such as name, surname, date of birth, function and etc... OK! Until then we have no problem, but this employee has associated with him the sales targets that need to meet, IE, in each month of the year I have a value "hitched".

If we were to imagine the relationship between such entities, I soon created something like this:

An employee has many goals, which in turn has the months of the year.

Below are the bean's sparingly:

public class Funcionario implements Serializable {

        private static final long serialVersionUID = 1L;

        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Long id;

        @OneToOne(cascade = CascadeType.PERSIST)
        @JoinColumn(name = "fk_metas")
        private Meta metas;

        ///Getters and Setters
}

public class Meta implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String ano;

    @OneToMany(cascade = CascadeType.PERSIST, mappedBy = "metas")
    private Set<Mes> meses;

    ///Getters and Setters
}

public class Mes implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne
    @JoinColumn(name="fk_ano")
    private Meta metas;

    private Double janeiro;

    private Double fevereiro;

    ///Getters and Setters... Meses restantes
    }

That would be the smartest way?

  • 1

    Why don’t you do it like this: Funcionario { List<Meta> metas; } and Meta { double valor; Date mesReferência; }? Since the month belongs to a particular year, it is normal to store it on a type date setting the day always as the first day. If you don’t like it, you still have the option to do so: Meta { double valor; int mesReferência; int anoReferência; }, although I prefer the first option because it will simplify a lot: the presentation of the date, the listing by period and the calculation between dates, for example.

  • So @Caffé actually the months will have to be fixed, because each month corresponds to an input where the user will put what the goal (value in real), will have to be reached that month.

  • 1

    And my model doesn’t fit? As far as I can see, it does.

  • So I must have misinterpreted it. I’m sorry, but I don’t understand. I’ll take a closer look at your proposal. Thank you

  • See if your model covers anything my model doesn’t cover, and feel free to ask.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.