Now that we have customers data, let's map our customer class that we wrote earlier to this particular table. Now for this, we need a few more dependencies. First, let me stop the server if it is running, because every time I make some changes, the server keeps restarting. And sometimes it becomes annoying. So let's go back to start.spring.io. Close this POM dot XML, and we want to add this time JPA spring data JPA provides a persistence mechanism to our application.
So let's click on that get the new version of the palm d'Or XML. Copy that to the clipboard. Let's go here, replace our current POM dot XML with a new one. And as soon as I do that, newer dependencies have been added to my project. And the first thing that I want to do is to specify information about the DB and that I can do better Going to the application dot properties, add a couple of JPA related information. Number one is what is the driver class that we want to use.
So this is done by giving spring dot data source dot driver class name equals to our dot hits two dot driver is the value for the same next spring dot data source dot URL, you might get the value for this URL from our h2 client. Let's first disconnect and then copy this one and then paste over here. Similarly, I also want to give username equals to say password equals to blank so do not give any additional space. But along with this, you also have to give one more thing which is spring dot JPA dot hibernate dot DDL dash auto non. Now if you are familiar with hibernate, you know that there is something called HBM to DDL auto, where hibernate automatically creates the tables corresponding to the customer dot java that I have written to say that we already have a table and the data corresponding to the customer dot java we say that hibernate should not manufacture the new table in the backend.
Otherwise, your data along with the table will be deleted and newly constructed. So, let's save this and go back to customer dot java. In the customer or Java we have to say that this particular class corresponds to the customer stable. There are two annotations for doing this number one is at the rate entity. And this comes from Java x dot persistence package. This is required because JPA which is Java Persistence API will only consider classes that are marked with a direct entity.
Now since the table name is different than the class name, we may have to specify that exclusively by typing at the rate table name equals to customers. Once again, import the same thing from Java x dot persistence package. Though this is not case sensitive, it is a good practice to follow either lowercase or uppercase for the table names. One other thing that you may want to mention here that the ID is the primary key among the others. So I can say here at the rate ID, as well as if you want to say that this is automatically generated by a back end, we'll say at the rate generated value. Strategy equals to identity.
This is applicable for any column in the back end where auto underscore increment has been given. Now in case if you have not given autonomy called increment but still want hibernate to automatically increment this, then you can say a generator equals to increment. In this case, hibernate will automatically increment the value from the application rather than from the server. So since in our case we are given ID as auto underscore increment, I can roll back to strategy equals to generation type dot identity. The other values for this could be something like sequence sequence is applicable for Oracle or you can also specify that it is table. So where a specific table would be created, representing only primary key values, or you can let it go automatically by choosing auto here.
Now, in my case, I'm going to specify identity. If any of the columns or have different names than their respective field names, you may also want to annotate that by at the rate column. So in my case, All of them have the exact same name as the back end table columns. So I don't have to do that.