Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
`Task` Entity Implementation | Final Touches
Java Data Manipulation with Hibernate
course content

Зміст курсу

Java Data Manipulation with Hibernate

Java Data Manipulation with Hibernate

1. JDBC Overview
2. Fundamentals of Hibernate
3. Final Touches

book
`Task` Entity Implementation

It's time to create the final entity in our small project. Employees should have tasks. Therefore, the last entity in the project will be the Task entity.

Entity Creation

Our task entity should have fields such as:

  1. ID;
  2. Title;
  3. Description;
  4. Deadline;
  5. Employee assigned to the task;
  6. Task status.

Pay attention to the last point. The task status can easily be placed in an enum since we will have only 5 statuses:

  1. Not started;
  2. Started;
  3. In process;
  4. Almost finished;
  5. Done.

In the code, this enum will look like this:

With this enum, the Task entity will look like this:

Now we need to implement the DAO layer. Let's not dwell on this for too long, as you yourself have done this many times before. The Task entity has the following methods in the DAO interface:

The implementation of this DAO interface is the same as for other entities, so let's move straight to the service layer, where two methods of interest are also defined.

  1. Update the employee who is assigned this task;
  2. Update the task status.

These are the methods that managers and employees will use in our system. As the application evolves, we will add new methods that employees and managers need. Because we have made our code extensible, adding a new method is not a problem for us, as it will not conflict with other methods of this application. Everything is isolated from each other, and most methods of the Employee entity (for example) do not affect the methods of the Task entity. With some exceptions, of course, but more than half of the methods are isolated.

Let's finally take a look at the methods in the service layer:

The implementation of the last two methods will look like this:

There's nothing complex here either. Everything follows the template: setting a new Employee or Status and then updating the Task in the database.

Now, we need to test the functionality of this entity and the layers we have implemented. To do this, let's create 2 employees and one task in the main function. The employees will look like this:

The created object Task will look like this:

Now let's take a look at the functionality of the code:

Great, the foundation of our application is ready. We have implemented the logic for interacting with the database. In the next chapter, we will summarize and save this project as we need it later.

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 3
We're sorry to hear that something went wrong. What happened?
some-alt