Skip to content

create resol #1075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

romander333
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Hey there! 👋 Thanks for submitting your code. It looks like you've done a great job overall! There are just a couple of things we need to address before we can approve this PR:

  1. In src/main/java/mate/academy/hibernate/relations/dao/impl/MovieDaoImpl.java, the exception message in the add method is incorrect. It currently says "Can not save country to DB" but it should be "Can not save movie to DB".
  2. In src/main/java/mate/academy/hibernate/relations/util/HibernateUtil.java, please add a private default constructor to the HibernateUtil class. This will prevent the creation of HibernateUtil objects, as required by the checklist.

Once these minor issues are resolved, I'll be happy to approve this PR. Keep up the great work! 👍


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +4 to +6
import mate.academy.hibernate.relations.dao.impl.ActorDaoImpl;
import mate.academy.hibernate.relations.dao.impl.CountryDaoImpl;
import mate.academy.hibernate.relations.dao.impl.MovieDaoImpl;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good to see the imports for the DAO implementations. Ensure that these implementations correctly handle database interactions for their respective entities.

Comment on lines +13 to +15
import mate.academy.hibernate.relations.service.impl.ActorServiceImpl;
import mate.academy.hibernate.relations.service.impl.CountryServiceImpl;
import mate.academy.hibernate.relations.service.impl.MovieServiceImpl;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job importing the service implementations! Make sure these implementations are correctly utilizing the DAOs to perform operations on the entities.

import mate.academy.hibernate.relations.util.HibernateUtil;
import org.hibernate.SessionFactory;

public class Main {
private static final String COUNTRY = "USA";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting these constants into a configuration file or using environment variables for better maintainability and to avoid hardcoding values. However, it's not required by the task description.

import mate.academy.hibernate.relations.util.HibernateUtil;
import org.hibernate.SessionFactory;

public class Main {
private static final String COUNTRY = "USA";
private static final String ACTOR = "Vin Diesel";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting these constants into a configuration file or using environment variables for better maintainability and to avoid hardcoding values. However, it's not required by the task description.

import mate.academy.hibernate.relations.util.HibernateUtil;
import org.hibernate.SessionFactory;

public class Main {
private static final String COUNTRY = "USA";
private static final String ACTOR = "Vin Diesel";
private static final String MOVIE = "Fast and Furious";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting these constants into a configuration file or using environment variables for better maintainability and to avoid hardcoding values. However, it's not required by the task description.

fastAndFurious.setActors(List.of(vinDiesel));
MovieService movieService = null; // TODO: initialize this instance
MovieService movieService = new MovieServiceImpl(new MovieDaoImpl(sessionFactory));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good to see the service being instantiated with the DAO implementation. Ensure the MovieServiceImpl correctly implements the MovieService interface.

fastAndFurious.setActors(List.of(vinDiesel));
MovieService movieService = null; // TODO: initialize this instance
MovieService movieService = new MovieServiceImpl(new MovieDaoImpl(sessionFactory));
movieService.add(fastAndFurious);
System.out.println(movieService.get(fastAndFurious.getId()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line retrieves and prints the movie. Verify that the get method in MovieService and MovieDao correctly retrieves the movie along with its associated actors. Also, confirm that the toString() method in the Movie class includes the actors' information.

if (transaction != null) {
transaction.rollback();
}
throw new DataProcessingException("Can not save country to DB");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception message is related to saving a 'country', but it should be related to saving a 'movie'. Change the message to Can not save movie to DB.

@@ -54,7 +73,7 @@ public String toString() {
return "Actor{"
+ "id=" + id
+ ", name='" + name + '\''
+ ", country='" + country + '\''
+ ", country=" + country

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good to see that the toString() method includes the country information. This will be helpful for debugging and logging.

Comment on lines 6 to 15
public class HibernateUtil {
private static final SessionFactory sessionFactory = initSessionFactory();

private static SessionFactory initSessionFactory() {
return new Configuration().configure().buildSessionFactory();
}

public static SessionFactory getSessionFactory() {
return null;
return sessionFactory;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the checklist, you should add a private default constructor to the HibernateUtil class to prevent creating instances of this class.

public class HibernateUtil {
    private static final SessionFactory sessionFactory = initSessionFactory();

    private HibernateUtil() {
        // Private constructor to prevent instantiation
    }

    private static SessionFactory initSessionFactory() {
        return new Configuration().configure().buildSessionFactory();
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great job! 🎉 All the code looks good and follows the instructions, including the important fixes for the exception message and the HibernateUtil class. Keep up the excellent work! 👍


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants