Spring Boot Tutorial | Spring Data JPA | 2021

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on guys welcome to amigos code in this course i'm super excited because you guys have been requesting it for some time now and here it is so in this course i'm going to teach you everything you need to know about spring data jpa we're going to start off by understanding what exactly is spring data jpa then we're going to connect to a database so we're going to have a database where we can test our changes and more importantly how does the mapping from java classes to your tables in your database does work you will also learn about the hibernate entity life cycle which is really important for you to master spring data jpa you also learn about queries paging and sorting and the bulk really it's when it comes to relationships so one-to-one one-to-many many too many and more importantly understanding all of the annotations associated with these relationships you will also learn about transactions and a lot more so this course is what you've been asking for i've put a lot of time and effort on this course i hope you enjoy and you can access the full course on my website and i'm really looking forward to it without further ado let's kick off this tutorial springdale jpa is an amazing framework that abstracts all of the complexity needed for you to interact with your databases so if you're new to my channel go ahead and subscribe give me a thumbs up and if you haven't joined the private facebook group as well as discord go ahead and join i'm waiting for you there now spring data jpa is an abstraction on top of jpa and hibernate so jpa stands for java persistent api and basically it's a specification for accessing persisting and managing data between java objects so right here you can see that we have hibernate so hibernate is one implementation of this interface there are other implementations but hibernate is the most popular one basically what hibernate does in a nutshell it takes any java object right here and then we have this abstraction called object relational mapping which means that we can have a java class which we can then map to a database so that java class is represented as a table in our database and then we can perform various current operations as you'll see in this course and in here as i said spring data jpa is an abstraction on top of jpa and hibernate which makes it super easy for us to work with applications that needs to access database so it's all about the persistence layer right so spring data jpa reduces the boilerplate code that we have to write it gives us lots of generated queries as you'll see in this course and we can access our databases without having to write any single line of sql and that is through repositories which you will see in a second so it's really nice and where spring data gpa shines really is when you have is when you are working with spring boot applications so it makes the integration between spring boot applications and jpa in a much nice way without without you having to configure lots of things so this is spring daily jpa in a nutshell without further ado let's kick off this course for this course i'm going to be using intellij as the ide of choice and specifically i'm going to be using the intellij ultimate edition so we have two versions we've got the community and the ultimate now because we're going to be doing lots of database work in this course the ultimate edition gives us the database functionality right within intellij which means now we can see the tables we can see the indexes we can perform queries and it's super super nice as you will see throughout this course and one thing with the ultimate edition is that it's not free but there is a 30-day trial which you can use so i would definitely recommend you to use the ultimate edition if you can given that there is a 30-day trial however if you cannot use the ultimate edition for any reason go ahead and use the community edition which is absolutely free but it doesn't give us the database gui client so this is one disadvantage and as you'll see throughout this course i'm going to be performing queries joins creating tables all of that good stuff and you'll see how amazing this idea is so go ahead and download intellij and if you want to learn more about intellij i've got a full course just on intellij explaining how to use all the keyboard shortcuts navigation and all of that good stuff so if you want to download intellij the best way for you to download it is through this application called toolbox in here so search on google toolbox and then you can download all of the ides that jetbrains has to provide for this course i've prepared this github repository where you will have access to all of examples that you will code throughout this course so in here you can see that i've got this awesome image the course description and then check out branches so for each section in here we have branches so you can see that we have section one two three so at the end of each section i have committed the code so that if you are stuck you can refer to the source code but if you have any questions go ahead and engage on the private facebook group as well as discord so in here the main branch is the starting point so this is where we're going to begin our journey learning spring data jpa so let's go ahead together and click on code and in here let's grab this link so from ssh command c and then inside of intellij in here so this is the main page i'm going to say get from vcs and then i'm going to paste that and then clone just give it a second it's actually resolving all the dependencies and that's done now open up the project tab in here and you can see in here we have the folder structure so the folder structure is really simple so inside of source we have the main and then java and an application so this is a bare bones springboard application and inside of resources we have application.properties which i will explain in a second and inside of palm.xml this is the maven configuration so you can see some metadata in here i'm using java 15. so if you are using java 11 for example you can change this to java 11 and also you can see that we have a couple of dependencies in here but the one that we really are interested are these two spring boot starter data jpa and this one here so org dot postgresql so this allows us to connect to a postgres database this is pretty much the folder structure so as you can see it's really straightforward next let's go ahead and get the application up and running and for that we need to understand the application.properties in order for us to start the application let's go ahead and open up the application.properties and in here i already have this configured for you so you don't have to waste time creating all of this but let's go ahead and understand exactly what all of this means so here this is the connection url for our database username and password because it's it because it's local development we don't have to specify these specifically on a mac but if you're on windows and if your database has a username and password put those in here and you are good to go then in here we have spring jpa configuration specific so the first one is hibernate ddl auto and this configuration here simply means that create the schema and before the application shuts down drop everything so the reason why we have this configured like this is because we're going to test various different things with spring data jpa but i'm going to cover this property more in detail later down in this course then we want to see the sql statements that hibernate will generate here we are specifying the dialect postgresql and then we also want the sql to be formatted and this is pretty much the configuration that we need for this course now in here you see that we have amigos code so this is the database name so in here if i press command and then l and then do a backslash l you can see that i do have this database called amigos code now you can pretty much connect to any database that you have in here or if you want a brand new database all you have to do is say create database and then the database name let's say hello for example there we go and now you have the hello database inside of this server backslash l and you can see that hello it's here and in here now you would change this to hello right but for me it's amigos code because by default postgres app creates a database with the associated user so in my case amigos code for you it will be your username so once you have the database configured go ahead and press play there we go you can see that it is starting and there we go so it started correctly no errors everything is up and running fine if i stop this and if you don't see this play button let me close the application.properties in here inside of application dot java so this class you should see display button or you can just right click in here and then say run application and there you have it so we have now successfully cloned and started the application and from this point onwards we are good to go to learn spring data jpa one thing that i want to show you here is remember i said that we have all of the branches so if i click on this button here so we can see the branches and you can see all of the remote branches so section one section two section three so at any point if you want to check out any specific branch you can do it so let me actually show you so here let's say that i want to check out this branch so check out branch five or actually section five and you can see that immediately we have a bunch of new code so it's just resolving dependencies there we go and now if i start the application so this time it might take a while and you should and you should see a bunch of logging and there we go so you can see that's from sql and there you have it so also in here is if i press q in here and then connect to amigos code so amigos code and then do a backslash dt you can see that we have these three relations and for this course i'm not going to use the terminal because i don't want to be switching windows back and forth so everything that i'm going to show you is through here so in here we have this database tab in here and here we can configure the database and i'm going to show you in a second but from here we can actually see everything that everything inside of our database so there you have it now let me actually stop the application and then let me switch to main so main is the starting point and there we go right so we have the database up and running now inside of intellij let's connect to our database so here i'm going to click on this database tab and new data source and in here choose postgresql so for example if you want to experiment this course with sequel for example you can definitely do it but i wouldn't do it until we complete the course because i want you to get things working nicely and by the end of this course you will know everything you need to know about spring data jpa allowing you to connect to other databases without any issues so here let's first choose postgresql and then in here i'm just going to leave this as default so the name and you can change it if you want then the the host is localhost the port 5432 so that's the default if you have changed it then you need to change it here as well but for me it's the default then authentication user and password so because we are doing local development on a mac using postgres app we don't have to specify these and if you're on windows as i said before you might have to enter the user and password that you have specified when you configured your server then the database in here so instead of postgres choose the one that you have created so in my case this will be amigos and then code and i'm going to test the connection and you can see that it did work now if you see a pop-up that says you need to download the driver go ahead and do so so that you can connect to the database now i'm going to apply and okay and you can see right away in here we have databases one we've got the roles in here tablespaces if i click on database this is amigos code we have one public schema which is currently empty and in here so what i want to show you is so if i collapse this you saw that we have this console and this is where we can perform select statements so what i want to do first is i'm going to switch branches quickly because i want you to see that for example if i switch to section six so in here we learn about various different things including one too many many too many one-to-one relationships so section six checked out and i'm going to run the application and by the way you don't have to do this i just want to show you that from here we will get the tables and then we can perform some queries so there we go so you can see that the application started no issues if i collapse this and now if i refresh you can see that now we have five tables and four sequences so here you can see that we have book course enrollment student and student id and basically all of this here represents this erd diagram which you will learn throughout this course and how to build all of this so now if i go back and inside of this console here we can have select statements so here i can say select and star from and then student and we can join let's say we want to join to card and we can also join to books like that and if i run this you can see that in here we have the output and there you have it so this is why i want to use the ultimate edition because everything is integrated and i don't have to switch screens which makes things much easier for you so if you don't see this console what you can do is create a new console so here right click new and then query console and then you can perform queries you can say selects so on and so forth and the cool thing here is we get auto completion and it makes writing sql much easier than using the terminal if you want to learn about data grip which this is actually part of data grip so data grip is this awesome ide in here which i have installed so this one here so if you want to learn about data grip go ahead and check my free course on data grip where i teach um all of this basically this is a subsection of data grip embedded into intellij ultimate this is all for this video let me actually stop the application and again let me switch branches so make sure that you are in main from now on let me check out and there we go and then application.java should be empty as well as no extra classes inside of the main package this is all for now catch me on the next one let's begin by taking one table and then we're going to build the java class and then construct a table in our database so right here you see that i do have this entity and its name student and it has few properties id first name last name email and age and in here email should be unique and also you can see that the id is the primary key so pk and i also have the data type for them so here big serial not null meaning that the value must be present so it cannot be empty and the same for first name text not no last name the same email the same and then for age the data type is an integer so what we're going to do then is take this so this is our erd diagram and again we're going to start with student and then move to the bigger picture but for now let's start small so we're going to take student and then build the java class now in this class right here we have to define few things one we have to tell spring data jpa that this class student will be a table in our database and i'm going to show you this in a second and then we also need to specify the entity so these two are annotations that you will see in a second and then as with any java class we need properties so the properties will be the exact same ones that we have in our erd diagram but we will use some annotations that will tell that these properties are inside of our table so once we have everything configured then we should see in our database the corresponding table right now let's go ahead and open up intellij and what we're going to do here is the following so in here let's go ahead and create a new class inside of com.example.demo so here create a new class and the class name will be student and right here i'm going to say don't ask again and then cancel and now this is a class that will represent our entity in our database so here let's go ahead and define the properties that we need so first i'm going to define the id so private and then i'm going to say long and this is the type of the id right so here let's say id and then we also need to specify the first name so private and this will be string first name private string last name and we need email and finally we need the actual age so private and then this will be integer and this will be h just like that and that would semicolon now let's go ahead and add the getters and setters so here i'm going to press ctrl and then enter and here i'm going to say getter and setter so select all of that and then okay and finally oh actually not finally so first let's have the two and then string and select all of those as well and make sure you use um the plus so you have actually different implementations but let's just use the one that intellij gives us by default okay and right here what we are missing now is the actual constructor so let's go ahead and add the constructor there we go so i've just pressed ctrl enter and then select all of those okay and there you have it so let me put this on it's on a new line just like that so right now this is our student we've taken this entity from our diagram and we've built a java class so right now we're not using spring data jba so so far we have just a class with some properties and you can see all of these properties so five properties right here they correspond to our design right here next let's go ahead and tell spring data jpa that we want this class that we've just created we want it to be a table and also we want we want these attributes to be a column in our table to map this class to a table we need to use this annotation called at and then entity so the package that this should come from is java x dot persistence so you can see that we also have org.hibernate.annotations and we should avoid everything from hibernate and use everything from java x dot persistence because if you want to change for example from hibernate to a different provider nothing will break so here choose the first one and now in here we need to basically we can just remove this for now and let me actually show you what this means so right here you also see that we have this symbol which is really nice but now so if i show the diagram in here we've said that we have an entity so this student.java is an entity and then this is now mapped to a table in our database we also have this other annotation called table and i'm going to show you in a second so here let's go ahead and just run the application and see what happens and this gives us an error now if i scroll up you can see that the error says no identifier specified for this entity so when you work with databases is good practice to have identifiers i.e primary keys and in this case right here so our id is our primary key so here what we need to do is tell that this id right here is a primary key now the way that we do it is by saying at and not pound sign and then id so again have a look you've got two annotations so always make sure you choose the one from java x dot persistence so there you have it and you can see that we have these special symbols right here but let's go ahead and try and run the application again and there you have it so check this out so if i show you in the logs so you can see that the application started and then right here because we've enabled logging so right here so if i open up application.properties remember show sql you can see that we have this section right here where it says hibernate and then this is the query that it was executed against our database so create table student and then id age first name last name primary key as we specified so which means that if i open up my database in here and i think i need to refresh this there we go and you can see that i do have student right here so this is so nice so we haven't done much and we already have this class mapped to our database as a table so obviously we have to do a little bit more work to configure but this is the bare minimum that you need in order to map a class to a table in your database so if i also show you through the terminal so right here so if i do a backslash d you can see that we have now the student table backslash d and then t and then student or actually this should be backslash d student and you can see that we have the exact same thing right so id age and we also see that we have an index right here right so index student primary key and it's b3 so we have more work to do right here so remember we have some constraints so we said that this should be text not null and then this is a big serial which is backed by a sequence so we also have to change this but you can see that this is the bare minimum that you need in order to map a java class to a table in your database and one last thing that i want to mention to you is when you have your entities it's always good practice to add a name so in here in my entity i'm going to say name and then here this will be student so this will be so basically the default is the actual class name so student but it's good practice to be explicit about the name right here and i'm going to show you exactly later on where to use this name right here but for now if you don't specify the default will be the same as the class name but it's best practice to have full control and specify the name yourself because sometimes you might have a really long class and then the entity name might be different so let's say that this is like student abc for example but you want to call it just student right you can do it and then in here later on you'll see where we're going to use this and it will make fully sense but for now let's just keep it like this now that we have this class mapped into this database let's go ahead and take care of these properties and configure it exactly the way we want so for the id what we want is a big serial and the big serial data type is backed by a sequence so let's go ahead and configure a sequence with our specified id so right here let's go ahead and say that we want at and then sequence generator and in here this will take a couple of things so we have to specify the name so let's go ahead and say name equals to and then student and then sequence we also have to specify the sequence name so comma and let me duplicate this because this will be the same so sequence and the name oops not emojis just like that we can specify the catalog the schema and the initial value is all but here what i want to specify is the allocation size so our location size and this will be one so this is how much will the sequence increase from we want to go from 1 two three four five and you can see that the default one so if i press command p the default initial value is one so we are good there so now that we have the sequence generator we need to say that this is at and then the value so the generated value for this will be so again within parenthesis so i'm going to say that the strategy will be a sequence so right here generation type and then sequence and here let me add this static import just like that and then here we need to specify the actual um the actual sequence name that we specified so command p you can see that we have the generator there and the generator is the one that we've just defined above so this one right here there we go and we are good to go now if i restart the app there we go so you can see that we have so we have create sequence student start at one or actually start one and then increment one so this is this value right here so increment one is the allocation size and then start at one is a default right here so now if i open up so in here i'm gonna open up the terminal and i'm gonna say backslash nnd there we go and you can see that we have the student sequence right here right so this is the name that we've specified in here so let me collapse this and let's see if we can see the sequence from here so here if i refresh yes there we go so you can see the sequence is right here as well so there you have it now our id is backed by a sequence which is the same as the big serial data type next let me go ahead and teach you about the at column annotation now let's go ahead and learn about the add column annotation so right here if i open up the database you can see that let's have a look at something here so we have so if i collapse this so in here we have the id right here which is this id we have h right here which is this one and then we have last name so this one is important so last name you can see last name right here and instead of being last name camel case it's now with underscore so there are times where we want to have full control of the name as well and it's good practice to specify the name that we want for our columns so here what we need to do is as simple as let's go ahead and add a at column for every single property that we have so here at and then column and in here we can specify a couple of things so for the id for did what we want is to say this will be name so let's just say on a new line we want name equals two and then this will be id and we also want this to be updatable to false basically we don't want no one to update this column and you can see that we can specify some other attributes and you'll see this in a second so now let's move on to first name so i'm going to say add and then column and here this will be name equals to and then first and then underscore name so if you want to change this for a different name you could absolutely do it but this is what i want and also right here you see that we said that name is text not no so here the way that we do this is as follows so to say that a column must not be null because right now it can be no so we say this so if i press command p you can see that we have nullable and the default is true so i'm going to say nullable and then false and also i want the column definition to be and then text because right now it's varchar255 and i want to be text and that's it to be honest so let's take this and then paste it here because this will be the same but this will be last and then name just like that add a space and they should also have a space there and yeah just like that and let's do the same for email so i've just pasted that so email and right here nullable and then the email this will also be text but what i want for this email is to be unique right here so unique and true right so right here you can see that we have a unique constraint on the email so that's for email and then age so right here for age all we have to do is say column and then here i'm going to say name equals to and then h that's really it what i want for the columns and there you have it so now if i run this and also you can see like we have these quickly red lines and i want to show exactly what this is in a second uh but if we run this so this is not stopping us from compiling and there we go so you can see that we have a couple of things but now have a look so have a look so in here we have altered table and then add constraint and this is a constraint name right here so if i expand database and let me collapse this for now and then refresh in here you can see that now things have changed and we have a couple more things so id age so nothing changed there email this text first name last name and then we have a couple of constraints right here so the unique constraint for the email and also the index for email right here so you can see we have an index as well as this constraint and the name is kind of ugly and i'm going to show you exactly how to fix this in a second but for now there you have it we have now fully adhere to our erd design right here and actually i think we forgot to add a not now on age so in here so let's go and add d right here comma and then nullable equals to false and there you have it so next let me go ahead and show you how to fix these red squiggly lines right here right the reason why i see these red lines right here is because i'm using the ultimate edition and this gives us um you know extra features so what we need to do is actually if i put my cursor there so right here it says that cannot resolve age assign a data source and let's select the amigos code localhost okay and you can see that the red lines disappeared so basically this now um gives me the flexibility of so right here on the left hand side if i click on persistence you can see that i do have access to a couple of things here so we have student and you can go through the columns right here but we also have the um abstract persistable and then auditable so this is um jpa specific which you don't have to worry about for now so there you have it and also one thing that i've noticed is that in here if i scroll up i still have this red line and this is um intellij telling me that i need to create a no r constructor so let's go ahead and do that and there we go and now all of the errors went away so next what i want to show you is go to database so right here you can see that we have this unique constraint right here so this name right here it's like really ugly like uk and then whatever and basically we want to have full control of this name right here so let's go ahead and learn how to tackle that next all right so to change this unique constraint name right here is as follows so right here let's go ahead and use the at and then table so the same way that you saw we have at column at entity we also have at table because right here the name of the table is the same as the class but lowercase so what we're going to do is we're going to take full control of that so we're going to say that this name will be student but also in this table right here we want to specify some constraints so here if i press command p you can see that we have unique constraints so let's go ahead and say unique constraints and right here this takes an array so i'm going to add curly brackets and then inside i'm going to say add and then unique constraint and then we need to specify name so here i'm going to say name equals 2 and we also need column names so let me just put this full screen so you see exactly so here the column names we can also pass an array of columns but i just want the email so this will be just email and then here this is where we specify the nice name so here i'm going to say student and then email and then underscore and then unique just like that i know the name it's a bit long but it's way better than having that random name so now what i'm gonna do is actually run this because i want to show you something so there we go and right here i can see that the constraint name right here hasn't changed still is uk and then this random number right so what's happening is that let me actually show you so in here so if i refresh you can see that still with the exact same name oops so let me actually collapse this again i'll actually expand this and you can see the random name so the reason why that's happening is because we have defined the uniqueness in here so in this at column so if i search for so here command p there's no way for us to override the unique column constraint so what i'm going to do is remove this unique from here and now if i restart the application and in fact this should go and then run there we go now check this out altered table student add constraint student email unique and then the unique constraint so here if i refresh this now you can see that the name is now correct and this is exactly what we want so there you have it so we actually managed to pretty much do everything from this diagram we've taken this entity we built a class that represents an entity and the entity maps to this database that we have and we actually took control of the columns by specifying the actual names that we want the same with add table and also the unique constraints as well as the column constraints right here so text not no we've managed to do that and we also managed to create a sequence for our primary key and this is all for this section in this section let's go ahead and learn about repositories and how they help us to manipulate our entities in our databases so right here you saw that we've taken this erd diagram so student we built a java class and then we map the java class to a table in this database so currently that is all that we have now we need a way to be able to perform some current operations so create read update delete and possibly have custom queries that we can perform against our database so with spring data jba we have this concept of repository and the repository is simply a data access layer and the goal is to abstract everything which reduces the amount of boilerplate code required to implement data access layers so in here you can see that what we're going to do is have this student repository and this repository will be our data access layer and this means that now we can add new students we can delete students we can search students we can modify students so on and so forth now when we work with repositories we need to extend the following so we have couple of interfaces that we can extend from so we have the jba repository and this includes some jpa methods as well as the credit operations but more importantly it includes flesh and batch functionality which you'll see in a second so jpa repository extends paging and sorting repository and this repository is mainly when you want to perform some pagination and sorting and this repository extends crud repository so this repository gives us some cred methods and you'll see this in a second so basically this repository so our repository must extend one of the three so jpeg repository paging or cred repository so let's go ahead and look at these interfaces so i'm going to open up intellij and right here i'm going to search for cred and then repository and let me collapse this and you can see that this repository gives us these methods so save save all find by id exist by id final count final by id delete delete all and basically you know the basic of credit operations so let's have a look at the jpa repository so jpa and then repository so there we go so this one as i said extends paging and sorting so right here so jpa extends paging and sorting and you can see right here so you can see that we have find all basically almost the same methods that we had with credit repository so save and flush which i'm going to talk to you about later and basically that's it right and let's have a look at the paging and sorting repository so this gives us the ability to pretty much just find by sorting and also by paging so this is very important when you want to perform pagination so and also you can see that this extends cred repository as i said in here right so extends correct repository now what is really important is that you can see we have this t and an id the same here so these diamonds so this is generics so the same in here and in here and if i go back to jpa repository you can see that we have the same so this is working with the with generics and the same with credit repositories so generics right here so if you want to learn more about generics go ahead and check my course on generics where i explain everything you need to know about generics so that you understand what is happening but in a nutshell what this allows us to do is to pass any entity that we have and it's data type for the identifier so the primary key and then we can use it to perform all of these operations so save save all find find all so on and so forth now that we have an understanding of how this works next let's go ahead and create our student repository and save some students to our database right within intellij let me go ahead and open up the project tab and what we're going to do here is create a repository for our student entity so here what we can do is create a new class and this has to be an interface and go ahead and type student and then repository and there we go so now we have this interface right here and now we have this interface right here so currently it's not doing anything because we haven't extended the repositories that we can choose from so in here either one of these two oh actually these three right so here let's go ahead now and say so if i put this full screen let's say extends and then jpa so jpa repository and this comes from org springframework.data.jpa repository and this is the interface so now what we need to do is actually so in here if i um select or actually navigate to this class so command and then click on it you can see that we need to pass the type that we want to work with as well as the id so the type in here so what we need to do is the following so the type is student so that's the student class that we have and then the id is long now if i open up the student class so student class right here so in here you can see that the id is long this is why i've said long in here right so remember i said the entity as well as its identifier data type which is long and to be honest this is everything that we have to do in order to extend a repository and be able to use it so obviously within this repository here we can have a couple more methods which i will show you in a second but for now this is the bare minimum that we need in order to interact with our database now let's go ahead and open up application.java and in here let's go ahead and create a a method and we're going to say command line runner and this is so that we can have some code running after the application startup so here what we're going to do is the following we're going to inject the student and then repository just like that there we go and now we have to return so in here and this receives some arguments which we don't really uh care at this point and then semicolon and also annotate this with add and then bean and there you go so now this means that if i say student lot and then oh actually student repository dot you can see that now we have all of these methods right so we have get one delete find all find all that takes an example and this is um this is to do with some querying find by id flash save all and you can save as well here you can save a student so on right so let's go ahead and say save and then s and in here we have to pass a student so what we're going to do is say new and then student and what we're going to do is take this student outside so right here let's call it maria and then end up with semicolon now for the constructor we have to pass a few things so we have no arg constructor or we have the one where we pass the id first name last name so on and so forth so what i want is inside of this student class i'm going to remove the id from the constructor because the id is generated for us remember it's backed by a sequence and we don't have to do anything there so just like that and remove id from here now if i go back press command p you can see that we only have to pass first name last name email and then age so let's say maria jones and the email is maria jones at amigoscode.edu just like that for education um and then for age let's say that she is 21. so in fact let me put this on a new line and there you have it so make sure not to type the first name and then column and then maria so strings because this is some help from intellij so don't type this only type this string right here and then what we do is we call the repository and then save right here so now let's go ahead and start the application and there we go you can see that worked but now check this out so in the logs we can see that hibernate performed an insert into student and then it passed the age email first name last name and the id right because the id is managed by the sequence and we didn't specify and then it passed the actual values in here so this means that now if i check my database and in here we can jump to query console and i already have one console open in here and i can just collapse this now i can say select star from and then student and if i run this you can see that we have the output and what i'm going to do here is i'm going to say that i want this to be transpose and check this out so now we have one record in our database and this is really cool so let me open up psql backslash and then x and this is to get the expanded display on and then select start from and then student and the exact same result so there we have it so you can see how easy it was for us to be able to have a custom repository which serves as our data access layer and then manipulate our entity in our database so if i go back to application so you can see that from now on we can use any of the methods provided by this student repository to interact with our database if you have any questions go ahead and let me know otherwise let's move on you
Info
Channel: Amigoscode
Views: 217,886
Rating: undefined out of 5
Keywords: amigoscode, spring boot jpa tutorial for beginners, spring boot jpa, spring boot jpa repository tutorial, spring boot tutorial, spring boot tutorial for beginners, spring boot api, spring boot crud, spring boot cloud tutorial, spring boot for beginners, spring boot full course, spring boot hibernate, spring boot hibernate mysql crud example, spring data jpa tutorial, spring data jpa vs hibernate, spring data jpa mysql, spring data jpa with h2 database, spring data jpa advanced
Id: 8SGI_XS5OPw
Channel Id: undefined
Length: 62min 2sec (3722 seconds)
Published: Wed Dec 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.