else apart from hibernate.cfg.xml in that particular case you need to make sure that you get pass that particular file name as the parameter is that clear to you so for example you might have named it as hb. CFG XML if you have done that when you call the method configure you need to make sure you pass h B do uh what did I say CFG doxel is that clear to you so this is what has to be done and after that if there is any annotated classes what do you mean by annotated classes uh what do you mean by annotated classes sorry all that entity class that you have created we uh which is the database that we are working on we created one table what is it student so for that particular student table we have created an equivalent class what is the name of the class that we have created a student itself so that class we call it as entity class normally it's a pojo class for that particular pojo class we have given at theate entity at theate table at theate column at the rate ID when we give all of these annotations it becomes entity class and that class is also called as annotated class because you have put annotations inside that class is that clear to you so you need to add that annotated class to the hiber net how do you add it by saying dot uh I mean you by calling the method add annotated class and you need to pass the class name over there what is the class name student so student. class is what you need to pass over is that clear to you after doing that you need to create a object of session and only then you'll be able to execute the program but if you need to create an object of session you need to First create create object of session Factory which will actually help to give the session object and after that you will start writing the code is that clear to you so let's quickly look at on these things if you were not able to grasp when I was saying all these things it means you have not gone through it or maybe you have forgotten so quickly let's go through all of it so let me open Eclipse and within this particular Eclipse if I come over here so this is not the one we are working on hibernate project is that the class that we are working on sorry project that we are working on if s then close all tabs okay inside this we have first of all pal. XML and inside this you have created the dependencies so two dependencies we have added one is the hynet dependency and the other one is MySQL connect apart from this what all have you done if you go back over here so if I go inside Java over here I have iberet CFG XML and if I open this particular thing you can clearly see you have a session Factory and within that you have multiple properties one is the driver class username sorry URL username password and the other one is dialect so you can see for all the others you are saying connection Dot and over here you are directly saying it as dialect and the other one is uh hibernate to ddl I hope you know what does that mean iberet to ddl and over here I have written as update there is another option that we have I will let you know about that particular option as well and one more is show SQL I made it as true what does it mean it will show you that SQL code internally whatever it is doing it will show that code otherwise it will not show you that code so this is this is that configuration file of iberet and apart from that we have also created the annotated class and this is the annotated class and you can clearly see uh what is the table name for this is student and we have also written it as entity and what is the primary key among all of this is ID and the column names also we have given for all the columns is that clear to you so every instance variable over here is equalent to a Colum column in the table so let's get back over here we have written one program where is the program that we have written we have written inside program one this is where I have written the program and what have I done is I have created the configuration object then I have told config do configure then I have told config do add annotated classes and we have added the annotated class then we have built the session Factory and then we have created the session and after that we have begin the transaction this is compulsory because by default Auto commit is true or false in hibern false but in jdbc it is true or false in jdbc by default it's true over here it is false so it is compulsory for you to write transaction. commit is this clear to everyone any doubts still here no great then so let's start writing uh the program for one by one over here what I have done is I have written the program how to insert the data correct or not yes now I want to actually uh let's see what all are the data that is available inside the database so let me take you to the database first so I shall open this I will name it as root okay let's get inside so we have the student table and inside student table we have uh CS department and inside that we have ID Department email name and percentage so let's add few more data into this so how do we add few more data into this just over here I can give the ID so I'll will give the ID as three let's name it as Charlie and after that we shall change this name from Bob to Charlie and over here I will say is from Mech and percentage is 80 if I execute automatically he will get added to it so it has got added similarly you want to add one more yes you can how do you do it I'll change the ID and which branch civil okay and we'll keep the percentage as 50 if I reexecute that also gets added and let's add another one Jack we will change this to Jack and this we'll make it as Cs and we'll make the percentage to 30 so I've just saved multiple data over here what I shall do is I will take you to our MySQL workbench let's quickly refresh and check what is the data have I got all the data present over here or not yes so it's a very simple thing I just have to create an object of that class and call the save method if I need to insert any data I don't have to write any query and who writes the query for me hnet and what query does it write same SQL query with the help of jdbc is what it will write so now what I shall do is I will get back to Eclipse so I'll create another program over here I'll say I want to create a class and I will name the class as be program two I need the main method I'll click on finish let's have a quick revision on whatever we had seen till now so can you please say what is that I need to start with I need to create an object of configuration how do I do it new configuration great and what object does it return is of config great after this what should I do next ah I need to say config dot configure now when it when it comes to configure you have multiple options over here you can there is one configure which accept zero parameters the one which accept zero parameters will actually check for hibernate do CFG do conf uh XML but you can also give the file name over here if you you say hb. CFG XML then it'll go and look for hb. CFG XML if it is there inside some other path you know how to create a pointer to a file or not you remember in some jdbc or somewhere we created new file blob clob you remember over there we created one file pointer you remember that ah same way we can create one file pointer which will point to a file and you can pass the file pointer as well well over here but we don't have to do all of that as of now I'll pass an empty one and will it return me an object or not configure method will it return me an object or not what object does it return config object itself it will return so what I will do is I will say config 2 great after calling the config method what is the next thing that I need to do sorry I need to add the annotated class so I will say config 2 so config 2 dot add annotated class and what is the name of the class student so I'll say student do class does this return me anything yes it does return me the configuration object I will name it as config 3 three after all of this what is the next step sorry simply session I should I should say sorry H I need to say config 3 dot sorry Bill session session Factory oh build session Factory okay I'll say build session Factory Factory it gives me an object of session Factory I will name it as session Factory what is the next thing that I need to do I need to say session Factory and I need to get the session from this so I'll say session Factory do get session oh sorry what Open Session great so I will say Open Session which will give me an object of session next what is the next step that I need to do sorry uh if you do this much you are ready to write hynet program but the problem over here is by default Al to commit is false so you need to get the transaction object as well how do you get the transaction object with the help of session or session Factory s session how do you say session dot begin transaction great it'll give you an object of of transaction so I say transaction next what you need to do uh now you need to write the code so how do I write the code all I need to do is session dot I need to save or uh transaction do save transaction very good session Dot and you need to say save and over here what you need to pass you need to pass the object whatever you want to save that anyways I will write it down and after that you need to say transaction do commit is this clear to everyone any doubts in this no now one thing I want you to observe I'll just uh comment this particular line because whatever you are going to do over here this is where you will start writing your logic rest whatever you have above this this is going to be the same for all the iberet programs is that clear to you yes no yes great now now you can see all the three whatever you have configuration configuration configuration are all the three of same type or different type same type and if you want to check it out you can clearly see one thing over here I will say system.out.println I will print config similarly I will print config 2 and I shall also print config three so if I execute this observe this carefully over here all the three that you see over here are the same object or different objects they are all same object whatever you are using to call the method the same object has been returned back to you is that clear to you so do you really think I need to save them and keep it yes or no no I don't have to save because I already have it at the first place why should I save it again for the second time and the third time I don't have to uh so I am going to do some modifications in the code observe carefully because from the next class onwards I'll will be copy pasting that particular first thing I'm saying over here I saying config do add annotated class is that clear to you so config 2 do add anotated class is what I'm doing where did I get this config 2 I got it from here so where did I get this one Whatever was over here that is what got stored over here correct or not so whatever I got from here I stored it over here and the same thing I used over here is that clear to you so when you are assigning this whole thing to this particular thing don't you think this and this is the same yes or no if you write X is equal to 5 so five and X is it same or not yes now don't you think this config 2 and this config 2 is it same or different it's the same thing so what I will do is if this is equal to this and if this is equal to this this whole thing don't you think this whole thing is equal to this one yes or no so I will replace this whole thing over here rather than storing it over here is that clear to you now how am I going to replace it if you ask me I will just copy this from here and I will paste it over here is that clear to you now if I do it over here am I calling the configure method over here or not yes do I need this line no so can I delete that line yes so I will delete this line I have deleted this line observe carefully again over here I wrote config do configure do something I have written but see this config where did I get this from over here now see this where did I get this from from this one is that clear to you so whatever is over here same thing is stored here and the same thing has been used over here now if this is equal to this and this is equal to this can I say this is equal to this a equal to b b equal to c a equal to C you know that right yes same logic I'm apply so my simple thing is rather than taking this storing over here and then using this over here can I directly use this over here or not yes so what I shall do is I will just copy this from here and I shall paste it over here now if I do this do I need this line or I do not need this line do not need this line so I shall delete this from you is it clear to everyone not just that observe carefully over here I wrote config 3. build session Factory now if you see config 3. build session Factory whatever I have got over here it's from here and how did I get over here this whole thing that you see that is what is config 3 is that clear to you it might look lengthy but it's the same logic what I applied just now so whatever you have over here you store it over here and then use that from here to year rather than doing it can I take this and directly paste over here or not yes so what I shall do is I will copy this whole thing from you and in the place of config 3 I will paste it if I do this do I need this first line or not no I will delete this line so automatically that was used only for once so I eliminated that particular thing so all I'm doing is configuration object whatever object I have with the help of that object I'm calling configure with the help of it will also give me an object whatever it does with the help of that I'm saying add anotated classes with the help of that I'm also calling this build session is that clear to you just for your easy understanding I'll put them in different lines for you or to make it easy for you to read is this clear to everyone so in every hibernate program you are going to write the same code so what all do you do you create an object you configure that XML file after that you add the annotated classes then you build the session Factory so that you can get the session objects once you get the session object you can start writing your code is that clear to you but when you write the code you need to start the transaction and you need to commit the transaction is that clear to you any doubts in this any doubts no so since we are using this throughout our code I will do one favor for you I will not write this code again and again and again rather what will we do ah we will create our own shortcut I hope everyone knows how to create a shortcut yes so all we need to do is copy this how do we create shortcut Windows preferences Java then editor templates you forgot I thought I taught you some great talents then after that you need to go to new and you need to give a name what name name shall we give uh HB I will give means hi bernet is that clear to you so pattern I will paste the code I have pasted it somewhere it should be there uh can you see that's there don't worry and some description has to be given hibernate template and I'll click on okay I'll click on apply and close and I will delete this code see the Imports carefully I will delete this as well I have removed this how do I get the shortcut HB control space program is ready from today this is how I write iberet so from today what is our focus on logic how many lines of logic one that's all so today you'll see how fast things will go so first of all it's giving me errors over here I hope you already know what is the reason for this errors do you know the reason for this errors ah it is because of input so if you want to write in a proper manner you can do also do this thing so I will what is the shortcut for UTS control shift o it is giving me two options because when it's importing it knows that is available in two places one is this one is this which one should I import or. hybernate do session Factory that's what you need to import so I'll just click on that and I'll press enter again over here it's or. hynet CFG doc configuration I'll click on that as well so it will select one by one then the orc dot there are always two two one is Java X and the other one is or so or dot is what you need and I'll click on AR all of the Imports are done you can see all of the Imports are taken is that clear to you now let's write the program it's asking for logic first of all let me say what is the question you have seen the database as of now correct or not how many rows were there in the database five rows were there now what I want is I want to fetch one row from this which row do I want to fetch if you ask me I want to fetch the row which has the ID equal to three is that clear to you if I want to fetch only one row how do I write the code for that there is a method the name of the method is get if I say get automatically I will get the object how do I call get whenever you call anything you need to say session dog so what I will do is I will say session dotg and when I say get I need to pass two parameters what are the two parameters the first parameter is from which class I want to get or from which table I want to get from which table am I trying to fix student table so I need to give the name of the class over there how do I give the name of the class I will say student dot class is that clear to you next what I want to do is I need to give an integer value over here now what is that integer value that I give over here that's nothing but the primary key that I need to give over there so primary key is what id so ID whichever is equal to three that's what I want so what I will do is I will say three over here is it clear to you now what will this thing do this get method is actually going to get the data how is it going to get the data internally it will write one command SQL command select star from student where ID is equal to 3 you you don't have to do anything it will write the command after it writes the command how many rows will it get one row in that row whatever is there ID name email then what do you have marks and Department it will take all of these things and then it will create one object and it will store all the details inside the object and then it will give that object to you and that object will be of which class student class so it'll do all of that and it will return you a object and you can clearly see is it returning your student object or not you store it inside the variable s and you can say system. out. print Ln is you will print that student object is that clear to you let's execute and check it out if you are getting the expected output so if I execute this you can clearly see select student ID then Department then email then whatever are the rows it is writing the query for that or not and at the we Clause you can see over here their student ID is equal to question and in that question mark what will be there whatever details you have given but at the same time it's also printing the student data but it is printing some hash code that is fully qualified class name with the hash code is what it's printing how do I change this I need to override the two string method so all I will do over here is I will override the two string method where should I overwrite in such student class so I'll come over here I will just override the two string method and what is that I need to do over here is super. two string I don't need what should I return ID I want a comma after that next uh name then I need a comma after that next email next Department then percentage percentage oh department is not D over here what do we call it as department so I need to write department and after that there is one comma and after that I need to write the perc St and if you want a closing bracket at the end you can also give the closing bracket by doing like this and if you want the opening bracket at the starting you can do that as well is this clear to everyone any doubts in this no and I will go back to the second program I'll re-execute the same thing you will automatically see it will say Char is that clear to you easy or complicated there is nothing complicated in so simple first day of java class if they had taught you you would have understood the problem is in that class you would have not understood what is class what is Constructor what is sets what is gets what is annotations that's a problem but it's a very simple thing but anyways I want for id4 let's execute are we getting the details or not yes because we have the details let's say ID is 40 do we have any details for this no so it should give the problem and the problem is what it's saying null because there is no object for that particular thing so it returns n any doubts in this no this is how you get one row of data is that clear to you shall we go to the next problem yes no the next problem is how do we get multiple rows of data normally I hope you know how to write the code in SQL to get multiple rows you know or you do not know yes no yes yes no no K or N O K thank you uh say then uh select select star from student from student student that's all no I want all the rows that's all you right yes sir yes so if you write this one so this is basically your SQL query correct or not yes so this is SQL SQL means what structured query language language great so in uh this whatever you said this is what table name correct or not yes this is table name in iberet how do you write the query if you ask me you write it like this from student that's all is the quired it's smaller than SQL or not yes no so this is actually a query I'm not joking you over here if this is a query this is also a query but the only difference is whatever you see over here this is not your table name rather whatever you see over here is class name and whatever class you have written over here this should be an entity class or annotated class this class is equivalent to a table correct or not which table is it equalent to this table so it will actually fetch all the details from this and then give it to you is that clear to you now this whatever you say is SQL so we call this particular thing as hql hibernate quiring language simple or not I'm not joking it's really hql there is a concept called as hql and this is hql iberet quiring language is it simpler than SQL or not yes SQL 8th standard students will learn hql engineering graduates will learn so anyways uh let's write one program to fetch all the details and check whether it works or not yes so let's do this so what I shall do is I will write uh create a new program so I'll create a class I'll name it as program 3 I need the main method oh sorry it's not visible for you now is it visible for you yes great so this is that hibernate thing I hope everyone remembers this I need to import all of this so I will import all of this I've imported each of these things now I need to start writing the query how do I write the query for for this is very simple put one double quotes and put a write a query what is a query from student uh s is upper case because that is not the what's name table name rather it is a class great so this hql query has to be passed now what is the method that we need to use over here if you ask me the method is not get over here whenever you are writing any hql query you need to say you need to call a method called as create query is that clear to you so how do I do it I just have to say session dot create query and over here you need to pass that particular hql is this clear to you it will return you one object what is that object is returning query object so this would have actually created that query and once it creates that particular query once it executes this particular thing what do you get would you get one are you fetching the data in this case or are you giving the data in this case fetching the data in this case when you're fetching are you getting the whole table or not yes you getting the whole table in that particular table one row is equivalent to one object or not yes is there one row in that or are there multiple rows in that multi multiple rows are there if there are multiple rows is there only one student object that will get created or are there multiple student objects that gets created sorry multiple students objects are created if multiple students object are created don't you think you need to store it somewhere yes where do you store it ah you can store in arrays you can store inside aray list you can store inside link list you can store it inside set you there are so many op options now where do you where is it stored if you ask me it is stored inside a list so what you need to do is you need to get the list of all those things how do you get the list with the help of quiry you can get that so what I will do is I will say quiry dot get what is that result list result list I think you remember uh result set that was in jdbc but over here you call it as result list what does it return it will return you a list of objects and all those objects belongs to which class all those objects belongs to student class if you get a list of objects do you know how to handle that objects or not yes you are all Java developers you easily know how to handle it so what I will do is I will just get a list of objects and inside this particular result set you will have the list of objects I will just say students now what is that I need to do is I want to print each of those objects how do I print each of those objects I need to write a loop for that so how do I write the loop if you ask me which Loop would you suggest for each Loop so I will write a for each loop I will say for I'll put a colon over here I will open it I will close it and on the right side of this what should I say students and on the left side of this what should I say ah you can say student or you can say yes it's up to you and what is the type of this student and it's giving me some error as of now why is it giving me error because over there I have not typ casted that particular thing that's the reason it is giving error so what I shall do is this I will make it as object itself as of now now it will not give me error but what I will do is while I'm printing I will try to convert into student so I'll say student system.out.print is now this object is actually of type student correct or not yes let's see whether it will call the student two string or not if it calls the student two string don't you think it will print the details of student yes let's execute this and check if you're getting the expected output are we getting the expected output yes that's all it is simple complicated jdbc is easy or hybernate is easy hibernate is easy jdbc is easy if you don't know collections obviously you'll say jdbc is easy this is so simple thing I don't know what is so complex in that nothing I don't know I felt iberet is very easy uh if you want to make a NE note of it you can make a note of these lines it might help you out e e are you done fine the next one is I have the student table within that particular table I want to fetch all the student details who marks is more than 70% how do you write SQL query for this uh select select star from student student next what do you say where sorry percentage percentage percentage greater than 70 is that clear to everyone any doubts in this so this is basically your SQL query let's see how does the hql query looks like where do you start from ah directly you can start from from that whatever you have over here is a table name but in hql query will you give the table name or class name class name so I will say from student so it's always good that you give alas Singh over here you would have studied alas sing in SQL similarly over here I'll say student s because in instance variables and all you would have seen how to access instance variable do you need a object to access instance variable or not yes similarly I'm doing that from student s so how am I referring that object by saying s now in this I need to write the we Clause how do I write the we Clause by same as SQL I will say where how do I say percentage I need to say s do percentage is greater than 7 so this is your hql code is it clear to you any doubts in this no fine then let's quickly write and check if you're getting the expected output for this so I'll create a new class so I have got whatever has to be there I've imported whatever has to be imported as well let's directly come and focus on the logical part what is the first thing that I need to do is I need to create the query how do I create the query uh from student s where s do percentage is greater than 70 great and whatever is there I need to pass this to one method what is the name of the method where I write hql query create query so what I will do is I will say uh session dot create query and over here I shall pass my query is that clear to you this will return return me an object of type query and whatever is a query that I have got with the help of this I need to get the list of objects now will there be only one object or multiple objects they can be zero or multiple objects how how many other rows are there so many objects will be created and all those objects will be added to the list and the list will be returned to me how do I get the list by simply saying quiry do get result list and after that I'll get the list and that's nothing but the list of students so I say students now all I need to do is write a for each Loop for this student so I will say write a for each Loop for this particular student is that clear to you that student object whatever I I have I'll will write it as yes and I'll system. out. print any doubts in this no exactly same as the previous program apart from this we Clause let's execute and check if you're getting the expected output so if I just execute it are you getting whatever has to be there or not above 70 whatever you have you got so similarly if you want to write we Clause if you want to increase the conditions you can increase the condition you can write or operator and operator like operator all of those things also can be used over is that clear to you so do you want to copy down this yes yes no okay fine so this is how you can fetch the data but if you can see over see the output over here this quiry that they are showing it looks in a single line it doesn't look good correct or not if select comes first then where comes it will look better correct or not you can do that as well how do you do that if you ask me you need to go inside this hibernate.cfg.xml over here you need to add one more property so I will say property and over here I need to give a name for that property and over here the property name is format SQL and that has to be made as true so what happens is automatically it will format the SQL for you now you can see this whole SQL query written in a single line correct or not now it will format that for you and it'll print it so now this is the select student. ID then student or Department email name percentage I think you have seen this in SQL yes no yes and after that from student again over here also they have done the same thing and after that we Clause has been written and you can see the we CLA over is that clear to you yes no great that's hyber so we are done with saving the data we are done with retrieving the data we have seen how to retrieve one row we have also seen how to retrieve multiple rows we have also seen how to retrieve multiple rows with we CLA as well is that clear to you and over here do we use SQL or do we use hql hql and in in case of hql what exactly do we do we do not represent the table name rather we represent the class is that clear to you so so that's all about it apart from this there is also update and there is also delete that we need to see so how to update and how to delete we will see in the next class is that clear to you so please go through all of these things probably from next class uh the environment would be quite different I mean you might be learning and coding at the same time because you'll have to build some projects and all of that is that clear to you great then if you're not installed not started please start don't wait ATT never fore fore fore [Music] for you for do May e What in you