Hibernate Tutorial 12 - Proxy Objects and Eager and Lazy Fetch Types

  Рет қаралды 275,560

Java Brains

Java Brains

Күн бұрын

Пікірлер
@namratam1522
@namratam1522 Жыл бұрын
Hi Kaushik, your teaching skills are exceptional!!! I am happy that teachers like you still exist in this world ! I am so fortunate to get to learn from you online !
@smrtfasizmu6161
@smrtfasizmu6161 2 жыл бұрын
I got that exception near the end. I didn't understand what's going on. So, I just went browsing about lazy loading to see what's going on. I expected to learn more about lazy loading in this video, I didn't expect to see the solution and an explanation to my problem immediately. Thank you!
@deepakjava3506
@deepakjava3506 4 жыл бұрын
I made my career in IT because of you.
@frankmyatthu2406
@frankmyatthu2406 11 жыл бұрын
Excellence explanation about Lazy Loading vs Eager Loading , Thank you sir
@Java.Brains
@Java.Brains 12 жыл бұрын
Yes. Any object that Hibernate returns could be a proxy. However, in this case, it's the User that needs to be proxied to support lazy fetch. It's a call to a UserDetail class getter that needs to fetch data on access.
@TheDanielBarcellos
@TheDanielBarcellos 10 жыл бұрын
one of the best tutorial i've ever seen! congratulations
@abhishekkumargupta9980
@abhishekkumargupta9980 3 жыл бұрын
These are very high class videos. Thank you Koushik. You have helped me learn many things.
@amsfuy
@amsfuy 11 жыл бұрын
It's really not exaggerated when I say that I love all your videos!
@brijeshwani101
@brijeshwani101 6 жыл бұрын
These are really awesome tutorials. Very easy to understand. Keep it up....
@niraj111981
@niraj111981 12 жыл бұрын
Very good explanation about Lazy nd Eager fetch..... Thanks..
@SumitKumarSahu79
@SumitKumarSahu79 12 жыл бұрын
Excellent video. It makes the JPA easy for me.
@reloaderify
@reloaderify 5 жыл бұрын
You are creating a world of well-informed developers. Nice work!
@MrDishajain
@MrDishajain 4 жыл бұрын
Very informative and detailed video.
@ashwinjayaram6954
@ashwinjayaram6954 8 жыл бұрын
very good tutorials Koushik. Thank you and pls keep up the good work.
@TheCreativityAddict
@TheCreativityAddict 11 жыл бұрын
happy teachers day Koushik!! Nice tutorials, really helpful
@Lallushe
@Lallushe 4 жыл бұрын
Very well explained. Thank you!
@munishtyro
@munishtyro 10 жыл бұрын
Your efforts are adorable !! thanx man
@vikasm80
@vikasm80 8 жыл бұрын
Very well explained the concept :)
@12345ms
@12345ms 13 жыл бұрын
These videos are invaluable, U're awesome thanks! mate
@rash805115
@rash805115 10 жыл бұрын
you are awesome...the tutorial is awesome...the world is awesome. Thanks. :)
@programacion3694
@programacion3694 7 ай бұрын
buen video, muy explicativo :)
@rohitjbhagwat
@rohitjbhagwat 8 жыл бұрын
Hibernate doesnt fire the select query if you just call user.getListOfAddresses(). it calls only when you are trying to get information of data inside collection like user.getListOfAddresses().size(). By writing user.getListOfAddresses() will print only the proxy object without the select being fired. Also there is no proxy of User class, instead the proxy object of collection is created.
@walecharohit
@walecharohit 7 жыл бұрын
Thanks man..I dint lykd his explanation about proxies
@adityasrivastava4048
@adityasrivastava4048 5 жыл бұрын
@@walecharohit i agree ,thanks Rohit Bhagwat
@adityasrivastava4048
@adityasrivastava4048 5 жыл бұрын
As per Koushik UserDetails proxy object is created, if it is a proxy object then why select query is being fired?, only proxy object of collection is created. whereas if we use load() method then it is not firing a query i think in that case proxy of UserDetails is created @JavaBrains could you please let us know?
@SurajBajaj
@SurajBajaj 11 жыл бұрын
KZbin has lot of entertaining videos. Please do watch them. This was meant for teaching Hibernate, which it does.
@walecharohit
@walecharohit 7 жыл бұрын
I am not getting any LazyInitializationException even on specifying the FetchType as Lazy :/
@crist2000a
@crist2000a 7 жыл бұрын
good tutorial indeed. However still did not get why Colletion Interface is used instead of collection implementation. In previous session it was said that it will be explained here.
@atamishali
@atamishali 7 жыл бұрын
Collection interface is used because if at any point in future we require to change the implementation (say we decide to use LinkedList instead of ArrayList) we can do this directly without making enough changes in code. This is called programming by interface rather than implementation.
@3SurajPatil
@3SurajPatil 6 жыл бұрын
Ali is right , what if I need Set implementation instead of List implementation. we can change directly the implementation class. or we can pass as a bean from spring.
@shanedetsch
@shanedetsch 7 ай бұрын
What eclipse hibernate plugin do you recommend using?
@Mladenac
@Mladenac 12 жыл бұрын
Defaults for Hibernate is always lazy fetching, but for JPA 2.0 (EclipseLink) is eager for some kind of associations.
@Exceptionhandler202
@Exceptionhandler202 11 жыл бұрын
you might already know that stuff but a totally new guy needs a little more details thats why i guess he explains it in so detail
@venkatanagasai7354
@venkatanagasai7354 4 жыл бұрын
Hi Sir, your tutorials are really good and explanation is very clear. I have a doubt running in my mind that i read several blogs about session.get() returns fully qualified object whereas session.load() returns proxy object. but, In the tutorial u have mentioned that the session.get() returns the proxy object and calls the base class methods. which one is true?
@swatimantri2441
@swatimantri2441 7 жыл бұрын
While debugging as explained in the tutorial I am getting address object as well. I don't understand then how this corresponds to lazy initialisation? If you could explain
@siddhaarth8843
@siddhaarth8843 5 жыл бұрын
Hi Koushik, excellent tutorials as usual, but I have a doubt : when I print the class of the retreived object using session.get(), it still shows the original class, and not some proxy class, why is this ?
@virupakshasg
@virupakshasg 12 жыл бұрын
Thanks for such great videos. Are you sure Hibernate creates proxy for User and not for Address? Address is what needs to be stubbed. I placed a breakpoint at session.get() and see that object returned is of type UserDetails (before cast as well). Address is of type PersistentIdentifierBag which seems to be a wrapper (proxy).
@mayurd23
@mayurd23 8 жыл бұрын
Does it mean every time we run 'select' operation, hibernate creates a proxy object and we call methods of that proxy objects only ?
@JamesJ30t
@JamesJ30t 9 жыл бұрын
@Java Brains One thing that puzzles if this Proxy class extends a base class. You cast using a base class cast would you not be calling functions from the base class?
@Java.Brains
@Java.Brains 9 жыл бұрын
JamesJ30t Nope. It depends on the instance you have. Think of it as a wolf in sheep's clothing. It's still a wolf underneath! Look up how polymorphism works.
@JamesJ30t
@JamesJ30t 9 жыл бұрын
Java Brains The confusion comes from working with c++. Upcasting (casting derived class to base class) in c++ access base functions and classes only. C++ and java differ on this. www.tutorialcup.com/cplusplus/upcasting-downcasting.htm
@JamesJ30t
@JamesJ30t 9 жыл бұрын
+Java Brains Did some testing one thing with Java is that when you upcast you can only access the procedures that have been overridden. That must be due to polymorphism. Also you only have access to the properties in the base class the subclass properties are hidden.
@asbalakrishna
@asbalakrishna 10 жыл бұрын
Superb Sir..........
@rogeroliveira4973
@rogeroliveira4973 7 жыл бұрын
Amigo, estou recebendo o seguinte erro quando tento fazer um GET em tabelas que possuem relacionamento: "java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: org.hibernate.proxy.HibernateProxy. Forgot to register a type adapter?" A meu ver a biblioteca Gson está tendo problemas ao receber a lista de objetos e converter para JSON. Sabe como resolver isso? Obrigado.
@raghebadel5689
@raghebadel5689 12 жыл бұрын
Thank you, it's great tutorial, i have a question, what does session exactly means ??? how can i manage sessions through my application
@aoozzooa4794
@aoozzooa4794 11 жыл бұрын
Hi Koushik! Thank u for such great tutorials. I have a question, kindly clarify. 1) Instead of session.get, if we use session.load, unless we access the non-primary entities of a model/POJO class, no fetching is done from the db. Can this also be called a lazy fetching? 2) With sesion.load, even if Fetchtype=Eager, trying to fetch a collection after closing the session, it still throws an error LazyInitializationException. Either case, using session.load is always a LazyFetching. Is that rt?
@SuperNunien
@SuperNunien 8 жыл бұрын
You say the list is fetched when the getter is called, but I believe it is when the list is actually used : user.getListOfAdresses(); // nothing is fetched user.getListOfAdresses().size(); // list is fetched
@curious_sapien
@curious_sapien 6 жыл бұрын
You're right
@AkashKeserwani
@AkashKeserwani 7 жыл бұрын
With new versions of Hibernate, I don't think this concept still holds. I am not able to make any lazy fetch scenario even after specifying the FetchType as Lazy.
@jonassx100
@jonassx100 6 жыл бұрын
same
@theworldminusraphtheninjat4378
@theworldminusraphtheninjat4378 4 жыл бұрын
mr i ahve a problem with lazy initialize i want to parse to JSON object i cant cuz of lazy initialize i have been stuck in this problem for a bout 4 month now and i still cant solve it the only way i found is to open multiple sessions to get one object like if i have multy level object like user inside it an obj of employee inside it an object of department it make my life hell pls if u know how to solve it in a better way help me some times the information is crucial and must be fetched one time but hibernate wont make me get but one eager fetch
@goodlifenepal
@goodlifenepal 11 жыл бұрын
Really useful thank you .!!
@surajankita1
@surajankita1 5 жыл бұрын
After session.close() if you r trying to fetch user.getName() it is showing the name?.How is it possible? because after session close all objects will be clear from cache
@programacion3694
@programacion3694 7 ай бұрын
the name was already loaded before sesion.close() so it dosent matter if you close or not, the member name is loaded when the session.get() retrieves from the db.
@qwerteeeeeee123
@qwerteeeeeee123 11 жыл бұрын
Hi As we will reach to user.getAddress, will load 100 of addresses but is there any way where I can specify to load the addresses who lives in bombay. in this I can only think of writig a query which get the data of bombay location, is there any other way in hibernate itself
@beyondthehorizon94
@beyondthehorizon94 7 жыл бұрын
Thank you so much, i love you
@daniellimbu9781
@daniellimbu9781 10 жыл бұрын
Hi koushik first of all, thank you very much for providing such a great tutorials. You are awesome.!! I am confused that I learned session.load() will only return a proxy object while session.get() will return real object that is instance of user class . But as you said in the video proxy object of user class is returned by session.get(). I am having confusion over here. Thanks
@anshuldogra7607
@anshuldogra7607 7 жыл бұрын
A late reply but what I understand is that session.get() returns us the original object via proxy object. But session.load() directly returns the proxy object without the original object coming into the picture.
@DeepakPandey-ij3bz
@DeepakPandey-ij3bz 8 жыл бұрын
I think session.get do not create proxy. Reasons are : 1.If constructor of userDetails entity is private then it will generate exception when we use session.load same scenario with session.get not throw exception. 2. For session.load JavassistProxyFactory creates proxy but in case of session.get there is a condition in Entity.class of hibernate. Below condition is false. if ( proxyOrEntity instanceof HibernateProxy ) { ( (HibernateProxy) proxyOrEntity ).getHibernateLazyInitializer() .setUnwrap( isProxyUnwrapEnabled ); } Also the fetchType is related to Collection as shown in @OneToMany (By default Lazy for @OneToMany and @ManyToMany) due to which lazy initilization exception was thrown. hese 2 things are different as per my understanding.
@IntergalaticSabotage
@IntergalaticSabotage 13 жыл бұрын
Great stuff!
@__vv__
@__vv__ 13 жыл бұрын
This is awesosme .
@remusik04
@remusik04 12 жыл бұрын
i agree. Thank you koushks
@quinnd6
@quinnd6 9 жыл бұрын
Yep as I said before the program has a problem for me. If I run it twice the second time I run it hangs on Hibernate: alter table USER_ADDRESS drop constraint FK_rr7b0tc5khp6fevg5vf9ctn5
@gillianbc
@gillianbc 9 жыл бұрын
+quinn d6 Try dropping the tables manually. Might be caused by renaming the table during our exercises and some references have been left behind.
@ialpha6431
@ialpha6431 6 жыл бұрын
Amazing if you were using Django querysets , they are almost the same.
@sanjay005
@sanjay005 6 жыл бұрын
I still didn't get why hibernate is creating a Proxy instead of providing user class directly.
@francesconuma
@francesconuma 12 жыл бұрын
I read an interesting question on stackoverflow. com/questions/5027013/hibernate-lazy-load-application-design about lazy loading entities in DAO layer. What do you think about? Regards. Thanks for your videos.
@farrukhahmedsid
@farrukhahmedsid 6 жыл бұрын
8:12 proxy diagram
@omidmohebbi742
@omidmohebbi742 6 жыл бұрын
Thank you a lot.
@gigel008
@gigel008 11 жыл бұрын
Wow... this was revelatory.
@rak2k1
@rak2k1 3 жыл бұрын
thanks you bro
@quinnd6
@quinnd6 10 жыл бұрын
Ah crap I'm getting this in eclipse. Hibernate: alter table USER_ADDRESS drop constraint FK_rr7b0tc5khp6fevg5vf9ctn5
@Adapt-wj5gi
@Adapt-wj5gi 7 жыл бұрын
You have good tutorials , but you have to explain this topic more deeply and give some others examples and problems with that fetching types!
@francesconuma
@francesconuma 12 жыл бұрын
thanks
@paranoid0792
@paranoid0792 11 жыл бұрын
why do you say so?
@walecharohit
@walecharohit 7 жыл бұрын
Not good explanation about proxy class.. :/
@puneethshivalingaiah
@puneethshivalingaiah 9 жыл бұрын
:) :) :)
@sunnydube
@sunnydube 12 жыл бұрын
Videos are good but when you explain the concepts IT IS THE WORST EXPLAINATION YOU WILL GET ON THE EARTH..... SERIUOSLY VERY POOR EXPLANATION OF CONCEPTS ...
@amogh12
@amogh12 11 жыл бұрын
i dinn ask you sob
@amogh12
@amogh12 11 жыл бұрын
your lectures are good ... I feel you waste lot of time talking ... its total unnecessary to go in that detail ... this really bored me and made me close video
Hibernate Tutorial 13 - One To One Mapping
12:52
Java Brains
Рет қаралды 307 М.
Hibernate Proxies - Why they’re used and How to Unproxy them
8:47
Thorben Janssen
Рет қаралды 4,2 М.
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
Hibernate Tutorial 08 - Value Types and Embedding Objects
13:18
Java Brains
Рет қаралды 264 М.
Lazy and Eager loading in hibernate
14:22
KK JavaTutorials
Рет қаралды 14 М.
Hibernate Tutorial 17 - Implementing Inheritance
14:59
Java Brains
Рет қаралды 191 М.
Hibernate Tutorial 16 - CascadeTypes and Other Things
15:22
Java Brains
Рет қаралды 221 М.
Solving one of PostgreSQL's biggest weaknesses.
17:12
Dreams of Code
Рет қаралды 223 М.
Hibernate Tutorial 11 - Configuring Collections and Adding Keys
15:00