CRUD operations using Hibernate 6 | Hibernate in Java | Hibernate #4 |

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 พ.ย. 2024

ความคิดเห็น • 22

  • @abhishekvermaa10
    @abhishekvermaa10  10 หลายเดือนก่อน

    Join our telegram channel t.me/ScaleUpIndiayt to get regular updates of stuff related to Java and our videos.

  • @sourabhboriya6282
    @sourabhboriya6282 4 หลายเดือนก่อน +1

    much needed video.

  • @PhoenixRisingFromAshes471
    @PhoenixRisingFromAshes471 7 หลายเดือนก่อน +2

    Loved your video. Keep making more on Hibernate.
    please make videos on Spring boot Microservices as well using some projects

    • @abhishekvermaa10
      @abhishekvermaa10  7 หลายเดือนก่อน

      Thanks for the support bro. In Hibernate, most of the topics are covered and series will end by April end. After that will start with Spring Boot.

  • @soumyamondal297
    @soumyamondal297 4 หลายเดือนก่อน +1

    Sir i wanted to know about the repository layer structure. Because i see you create your custom repository interface then you implement all those methods which is present inside the repository interface, sir it is required or not. Or one question sir in production environment we use hibernate annotations also or not. Sir i request you tell me all answers and also request you plz make a session on spring boot ,how to industry following the rest api structure they use always solid principles
    .. sir my english is so poor😢

    • @abhishekvermaa10
      @abhishekvermaa10  4 หลายเดือนก่อน

      Bro in these videos I am teaching to use Hibernate, hence we need to make own methods in repository impl. As a good practice we should always make interface for service and repository layer.
      Now coming on to production, so new projects are using Spring Boot with Data JPA. There you don't need to make implementation of repository. But Data JPA also uses Hibernate and if I will directly teach you Data JPA then you will never come to know about basics.
      So learn Hibernate by watching all videos and understand the code. I am going to start Spring Boot very soon and will cover Data JPA, REST API, SOLID principles and all other best practices as per industry.
      Your English is better than mine.

  • @DummyAccount-c1n
    @DummyAccount-c1n 11 หลายเดือนก่อน +2

    there is one method called transaction.begin() just like transaction.commit(). should we use this just after creating the transaction object? or its a optional

    • @abhishekvermaa10
      @abhishekvermaa10  11 หลายเดือนก่อน +1

      These are basically 2 different approaches:
      Approach 1: session.beginTransaction() - This approach will start new transaction and return it. You don't need to invoke begin() method again after this (invoking will be useless). This is best approach and hence in all demos we use this.
      public void saveOwner(Owner owner) {
      try (Session session = sessionFactory.openSession()) {
      Transaction transaction = session.beginTransaction();
      session.persist(owner);
      transaction.commit();
      }
      }
      Approach 2: session.getTransaction() - This approach just returns current Transaction object. After this we need to start Transaction by calling begin() explicitly.
      public void saveOwner(Owner owner) {
      try (Session session = sessionFactory.openSession()) {
      Transaction transaction = session.getTransaction();
      transaction.begin(); // begin() returns void
      session.persist(owner);
      transaction.commit();
      }
      }
      Do let me know if I was able to resolve doubt.

    • @DummyAccount-c1n
      @DummyAccount-c1n 11 หลายเดือนก่อน

      Thank you Sir, very much clear
      got it.@@abhishekvermaa10

    • @DummyAccount-c1n
      @DummyAccount-c1n 11 หลายเดือนก่อน

      but sir one thing , I am getting one error while executing ownerRepository.deleteOwner(2);
      Exception in thread "main" java.lang.IllegalArgumentException: Unable to locate persister: java.lang.Integer
      at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:978)
      at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:903)
      at org.hibernate.internal.SessionImpl.remove(SessionImpl.java:2383)
      at com.scaleupindia.repository.impl.OwnerRepositoryImpl.deleteOwner(OwnerRepositoryImpl.java:57)
      at com.scaleupindia.StartClass.main(StartClass.java:36)
      Caused by: org.hibernate.UnknownEntityTypeException: Unable to locate persister: java.lang.Integer
      at org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.getEntityDescriptor(MappingMetamodelImpl.java:388)
      at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1487)
      at org.hibernate.event.internal.DefaultDeleteEventListener.deleteTransientInstance(DefaultDeleteEventListener.java:170)
      at org.hibernate.event.internal.DefaultDeleteEventListener.delete(DefaultDeleteEventListener.java:158)
      at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:97)
      at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:84)
      at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127)
      at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:972)
      ... 4 more
      pls get me idea why it is?@@abhishekvermaa10

    • @abhishekvermaa10
      @abhishekvermaa10  11 หลายเดือนก่อน +1

      May i know which modifications you have done.

    • @DummyAccount-c1n
      @DummyAccount-c1n 11 หลายเดือนก่อน

      no modification sir, I did the same as you did. just called the delete repository method in main method
      public void deleteOwner(int ownerId) {
      try (Session session = sessionFactory.openSession()) {
      Transaction transaction = session.beginTransaction();
      OwnerDTO owner = findOwner(ownerId);
      if (Objects.nonNull(owner)) {
      session.remove(ownerId);
      System.out.println(ownerId + " is deleted successfully..");
      transaction.commit();
      }
      }
      }
      // calling the deleteOwner method in start calss
      public class StartClass {
      public static void main(String[] args) {
      OwnerRepository ownerRepository = new OwnerRepositoryImpl();

      ownerRepository.deleteOwner(1);
      }
      }

  • @usersk211
    @usersk211 9 หลายเดือนก่อน +1

    how to get List of objects ?

    • @abhishekvermaa10
      @abhishekvermaa10  9 หลายเดือนก่อน

      I deliberately didn't kept this in initial video because for this we need to take help of HQL or Criteria Builder. I will be making detailed video on HQL and Criteria Builder in coming days as part of this series.

    • @usersk211
      @usersk211 9 หลายเดือนก่อน +1

      @@abhishekvermaa10 sure Sir make video asap.

    • @abhishekvermaa10
      @abhishekvermaa10  8 หลายเดือนก่อน

      @@usersk211 work in progress buddy

  • @shortseverything138
    @shortseverything138 6 หลายเดือนก่อน

    How to set dtd...? Error

    • @abhishekvermaa10
      @abhishekvermaa10  6 หลายเดือนก่อน

      Didn't got your question.

    • @shortseverything138
      @shortseverything138 6 หลายเดือนก่อน

      @@abhishekvermaa10 ques is when we r apply dtd after we got error. Nd error is external source is disabled on last line of dtd