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😢
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.
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
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.
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
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();
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.
Join our telegram channel t.me/ScaleUpIndiayt to get regular updates of stuff related to Java and our videos.
much needed video.
Thanks bro
Loved your video. Keep making more on Hibernate.
please make videos on Spring boot Microservices as well using some projects
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.
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😢
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.
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
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.
Thank you Sir, very much clear
got it.@@abhishekvermaa10
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
May i know which modifications you have done.
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);
}
}
how to get List of objects ?
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.
@@abhishekvermaa10 sure Sir make video asap.
@@usersk211 work in progress buddy
How to set dtd...? Error
Didn't got your question.
@@abhishekvermaa10 ques is when we r apply dtd after we got error. Nd error is external source is disabled on last line of dtd