JPA Buddy – From Zero to Hero | @MarcoCodes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
it is common to work with applications that store data and use popular jpa implementations like hibernate Eclipse link and many more what should not be common is that we developers often struggle with many tasks such as creating or managing jpa model data repositories GPA entities and others and how can we forget the usual suspect handling database migrations or even creating jpa models using existing Legacy databases and you know this is just a tip of the iceb there are so many more issues that we developers struggle with on a daily basis do we know how to address all of them I don't but our speaker today definitely does hi everyone thanks for joining in for another intelligent idea live stream I'm your host Mala Gupta and now let me add our speaker Marco Bella to the stream hi Mar welcome Marco it's a pleasure to have you present with us today it is a pleasure to be here Mara I'm so looking forward to this as always so let let me quickly introduce you Marco is my colleague a fellow developer Advocate Richard Java with jet print sorry I'm Java developer Advocate and keep saying Java so Marco is also a great conference speaker and he has a very popular YouTube channel which is Marco codes so Marco are you missing saying Marco codes in the beginning of the session I'm missing saying Marco codes that's why I have to do it so Marco codes today yes that's amazing so I know that you are trying uh you will be talking about a lot of features for jpa bu so that people can um level up from being uh Zero to Hero when I would like to ask you this question which is your favorite feature from TBB it's an interesting question because there's so many features and I'm just going to give you a quick teaser because I think at the end of the day I like the coding assistance a lot where you literally just write a couple of words and you automatically get repositories queries dto everything created for you with very little you know effort so to speak so you'll see it in action um and I would say the these tiny Cod and Tiny the these great uh code assistance features are killer features for me I I'm not denying any of this that was a trick question because this is a question that I always read because people come up to me and they ask Mala what is your favorite feature in intelligent idea and I say that really depends on what I'm doing because there's so many amazing features in so I will not take a lot of your time and I before I let you take this stage let me share some quick housekeeping details um Andre uh Sergey could we have the slides up so that everyone's watching could see uh what I'm talking about okay so everyone's watching they can use a YouTube chat to post a question we'll try to answer your questions as you post them we also have Andre with us today who will answer your question he works with inter dig idea team and has been developing various plugins to simplify coding using Frameworks like jpa and spring we'll also have Andrea answering your questions on the stream after Marco is done with his live coding and uh the session is being recorded that is one of the most asked questions and we'll Host this session on intelligy ideas YouTube channel and also on jet prce twitch channel so if you haven't already subscribed to our channels now is the time to do so and if you like today's session which I'm sure you will do not forget to like the video and now let me add Marco's screen to the stream yes so yeah so Marco I'll be backstage just call out my name if you need anything and have fun thank you Mara thank you thank you I will right folks uh so we're just gonna Dive Right In um well we're going to talk about jpa Buddy the plugin who would have thought and and as I already kind of mentioned I think if you're working with jpa hybernate or any jpa provider so to speak um or even just you know you want to write dto and map them from your entities to dto and work with spring data it is effectively a very very very cool and useful plug-in um I'm not going to show you any slides to convince you to try out jpa buddy as always what I'm going to do is live coding so we'll spend the next I don't know 40 minutes 45 minutes uh doing some jpa body live coding and at the end of the day hopefully you can take everything you've seen me do uh and use it in your own project right after tomorrow whenever you like all right so what I did is um where if people are watching my Marco Cod Channel if not please subscribe to the channel um I'm having this I'm I'm building this Google photos clone application right where I essentially have a website at the moment a spring boot application uh where I can store images and videos in a database and that's the application we're going to work with roughly it's also available online I will check I will post a link to the GitHub repo at the end of the session so you can clone it you can repeat everything you saw me do uh either with that project or as I said with your own project now um I'm going to go to intellig idea and just a couple of prerequisites obviously I have the project checked out it is a spring project it has spring data it has hibernate jpa um it has a mySQL database doesn't matter it could be any type of database my SQL H2 postgress jpa body works with every database type uh that there is out there and the only thing I did and you'll have to do is you'll have to install the jpa Buddy plugin uh so settings plugins right and then on the plugin somewhere here you'll see jpa body and just a tiny note if you have intellig ID the Community Edition so the free version you can install a plugin and you'll have a ton of features available but if you have intellig ultimate and you install the plugin you have even more features available so there's a slight difference between these two um plug-in versions and I can I'll try and think of whenever I show you a feature to tell you hey this is only available in intellig idea ultimate and at the end I'll also try and give you a link uh to display uh you the differences between these two versions right okay so I'm in my project um just to quickly show you my database um the database is very simple at the moment it only has one table a media table a media table has photos images movie movies all there is I wanted to make it very simple so you can learn the concepts understand everything later on go crazy with your own project where you can show to where you can work with 200 database tables right so we're here um on the left you can see there's at the moment there's only one entity it's the media entity how and which maps to to the media table how would I know that jpa body is now enabled is there a specific window do you have some sort of specific actions and this is something um which threw me off at the very beginning because there's multiple ways uh to deal with jpa body and I'm just going to quickly show you them and then I'm going to show you my favorite ways and then we'll get finally get going so first of all um if you have hibernate any jpa provider in your class path the plugin will automatically be enabled and here on the left you can see for example the jpa Explorer it's a tiny toolbar tool window rather tool panel which pops up here at the bottom where you can see hey uh here are my persistence units hibernate speak for your entities uh what are my database connections and you have a couple of actions where you can do stuff yeah create new entities do whatever that's one way of of of playing with jpa body second context dependent if you have an entity open for example my media entity you will see a nice little toolbar here at the top hopefully you can see that on the screen I'm just hovering around it with my mouse where you can see I have actions where I can add entity attributes where I could add life cycle callback methods in indcs and whatever yeah named queries and we'll have a look at these shortly that's another way on the right here you have a so-called toolbar which is called jpa designer it gives me flashbacks to dely I don't know if any of you worked with dely before a long time ago but essentially these actions that you can see here at the top they are the same actions you can see here in the toolbar so you can add attributes for example to entities you can add life cycle callbacks and here at the bottom in this panel you have for example all the information about your entity in this case uh for example is there a parent is there a base entity is a specific inheritance schema all in one place so you don't have to go you know through your uh to your Java class and you know make a mental model of all the annotations you're using and last but not least last way if you go inside a file an entity or repository alt insert also gives you options so alt insert you know lets you add the entity attributes and everything you basically can see in the toolbar so at the moment there's we saw I think four different ways of playing with jpa bodyy um we might I don't even know uh you know improve that in in in future versions to make it a bit less multi-dimensional but for now you can choose your favorite one uh I personally like the old insert way I also like um actually the toolbar here the right side so we'll start with that because now enough talking about the basics and the prerequisites and the windows and whatever we want to get started so imagine uh well I have my my media entity SLT and um I want to add a new field and in in Javas speak I'll just call it it's going to be a storage enum because I want to remember did my file my my image for example come from a local hard drive did did it come from S3 did it come from Google Cloud Storage now I need to you know get it right did it come from Azure yeah and all every other cloud provider there is so let's just imagine I want to add that enum to my media entity what I could do obviously I could go ahead and you know write my field here private or storage rather and storage and then think of the right um annotation or what I could do is I'll open up jpa designer here on the right I want to add an attribute I don't want to add an association or a basic type I'm going to go down to enum so I'll just double click enum here and a field pops up new enum attribute the type is easy it's going to be storage so I see all the enums from my project the field should be called storage the enum type should be of type string because by default I think JP's default is to store enums as a number in the database as an ordinal so so I'm just going to go with string here I could even say hey I want to have a specific length for example or I want to have it to be unique or specific jdbc type code whatever we don't have to worry about all of that I just want to click okay for now right and then what I can see is jpa Budd added you know my uh storage field with the right enumerated annotation uh gets and sets and by the way if you don't like that that the gets and sets are being put there I'm just need to put it on yeah let's do a rearrange code it it will put the gets and sets in the right place and off you go now you might be thinking oh Marco that was so simple that was just you know an enumerated field um I could have done it yourself yeah that's true uh I wanted to start with a very basic basic super basic example because I want to pick it up on Notch now imagine we have [Music] um um a new user entity because what I want to have is I want to have a media table and every media table should be a or every media row object should be associated with one specific user and every user can have many media Medias I'm not quite sure media I think it's just the plural right so it's a good old one to many many to one Association again what I could do is I could pick up you know the hibernate book uh which I always recommend Java persistence with hibernate the second edition and think about hey which annotation do I need and do I need to have the reverse mapping somewhere specified and how does all of that work or I'll just use the jpa designer here on the right I click attributes I click Association right and hopefully let me see is my ID hanging well if it if it is the double click isn't working so I'll just try it here right Association for whatever reason I couldn't just just click here maybe because of the zoom level there was some issue here um I want to add a new Association attribute so I want to have um from my media entity an association with a user entity but that entity doesn't yet exist so what I can do is I can just click plus here and it gives me a dialogue window saying hey let's just create a new entity on the Fly I'm going to call it user entity it has no parent here and uh it has an ID with Ty Long which is identity meaning autogenerated in the database I'll just click okay and here on the left you can see my entity was already created now back in my uh Association window um I can see that hey yes I want to have a reference to a user and then what should it be yes should it be a many to one a one to many many to many one to one and then what I found super useful because it confused me myself a lot of times now what is it actually many to one one to many thankfully there's a tiny note below which says well many to one means several media objects are associated with zero or one user objects yes that's what I want then I can go crazy about it being mandatory unique the Cascade type um let's go to the mapping type uh and that is if you've worked with jpa before do I just want to be able to go from media to user or do I also go want to go from user to all the Associated media objects that is what the bidirectional joint column is for right and again I would have to think about you know how to map that properly here I can you know just you know tick the right um radio button I think it is I'll just click okay for now now jpa buddy asks me hey you have this bidirectional relationship you need an inverse attribute the one I talked about earlier right and I'm going to call it media right and I'll just go with a defaults here you can go crazy with all these options I'm not going to show you all of them um I'm just going to click okay for now and let's see what happened because what happened is long story short in my media entity we have a new user field it's a many to one with a joint column that looks good when I go to my user I can see that I have yes a set of media mapped with this inverse attribute right as I want to many and that is exactly exactly what I wanted so I didn't have to Fumble around with my own mapping and you know making the the annotations work uh instead I just literally clicked a couple of buttons and checkboxes in a dely dialogue window sorry about that uh and uh everything was done for me automatically and it works when you look at the jpa designer um what you also can do obviously you can add these attributes for any type of Association one to many many to many and I'm not going to go through any more of these relationships but literally anything you can map with hibernate you can you also will find a dialogue for that uh with jpa body basic types like you know string whatever write IDs embedded IDs enums all of that works same goes for life cycle callbacks I mean this stuff is rather easy for example you want to do something after an entity was loaded from the database um you can write your custom logic here same with inds um maybe something a tiny quick note about name queries um maybe I'll just tease it right away because um what jpa bud comes with is a I call it visual query designer and I'm just going to tease it here now um where essentially I can say hey oh maybe I'll go through it so imagine I wasn't working with with spring data just with plain jpa hibernate if any of your of of of those Souls out there are here in this webinar and if I want to write a name query imagine I want to write a new I don't know I'm going to call find all Uh custom sorry about that the naming is a bit wacky and um I want to add a query condition I want to say for example hey I want that my file name uh starts with something and I want it to be an IGN case query and additionally and now the zoom level again comes into play here that should look a bit better if the zoom isn't cranked up so much um and for example the creation date should be I don't know less than something and then a couple of other options which I'm going to ignore I'm going to click okay let's see what happens what happens is that jpa bodyy added a named query with the named queries annotation here on top of my entity it's called user find all custom and you can see here is a nice little hql query select you from user in a join media where this is how the upper so the the ignore casing uh is is being implemented so we just upper upper everything and um that's it you get a nice little hql query you didn't have to write yourself again you just clicked through a wizard essentially and everything was done for you right I'll just quickly comment that out because um I'm not I'll we'll reimplement that again that very same query later on with spring data um but for now what I wanted you to understand the first big concept of the jpa body plugin is when you have it set up in a jpa project doesn't even have to be a spring data project then you can do with your entities whatever you like you can you know create you you saw me create a very simple storage enum you saw me create associations they can be as complex as you'd like uh you can you know create name queries everything let's I would call it entity management uh everything you want to do here you can do with the with any of the the ways I showed you earlier with jpa body that's one big well let's say conceptual block I wanted to show you the second big conceptual block um I don't know about you but out there you it depends a bit on the project what type of developer you are are you a let's say Java first programmer meaning you just like to write your entities first and then at some point later on you update your database tables or are you maybe a database first type of person where you just um you know add maybe new columns first in a database table and then you know later on put them into your entities and I'm not saying there's a right or wrong way to do it I personally myself have switched ways uh over the years but in any case we have to kind of sort out um how do we Sy changes from java code to my database or from my database to Java code and usually uh what people nowadays do is they don't just you know have plain SQL you know uh change log statements but they use a tool like fly or liquidas for example um to somehow somehow create these uh these changes and apply them to a database maybe even the production database now let's say there is if you remember be saying at the beginning uh jpa body uh kind of scans your class path and when I do an old in here in my let's see under resources because I want for example to create some some database change lcks I don't see specific um for example thway actions here at the moment for that what I want what I need to do is I need to go to in this case my gradel build file and I need to put Flyway on the class path right and as soon as I have Flyway on the class path I get I can you know uh execute Flyway specific actions with jpa body the same would work with liquid base sorry if you're liquid based user I just wanted to go with Flyway keep it a bit simpler here um but uh just so you know that always make sure to reme to refresh your class path uh as well and um at the moment my database table that I have it kind of maps I think if I open it up you'll see here is my uh here is my uh media table that one tiny table but now we have a new entity my user entity uh we have that new field the storage field and I would have to REM remember these changes right because at some point I want to merge for example my feature Branch to the main development line and then I want to have a change set where I say hey I just added these couple of fields and obviously I could just remember them uh or I asked jpa BL jpa buddy to help me out how does that work well what you could do is um here under the resources now that I added uh Flyway you can see there's a new action which is called Flyway version migration let's see what it does and and that tiny um window here has um quite a bit of power let's call it like that first of all you can say hey what is my actual state of the model so what did I just develop should I have a look at the database or should I have a look at all the Java classes my entities here for now I want to go with the model because we just changed the stuff up here in uh in my entity classes in my Java project then what do we want to compare this state to right so what should the diff be and the diff in this case should be the database my database table I have and I can select you know uh jpa body here my connection that I have set up and I'll quickly tell you in a second what that snapshot here uh what the snapshot here does but I'll just click okay and let's see what happens so you can see that it took a second and then here in the left I can see that hey jpa body says let's create a new migration where the first part is I want to create a new table called user that's right we needed that for our use entity then we add a storage field a column rather sorry to my media table that's right we also want to add a user ID uh column to my uh to to the media table and we want to add a foreign key constraint also we just click save and what what's happened is I just got you know a V1 SQL script here a Flyway script I just for spring boot I would have to put it into the DB migrations subfolder here under the resources but you get the idea uh you just got a perfectly valid uh diff uh differential change between your model and your database uh without you having to remember what you effectively changed and the thing is by the way I said at the beginning there's a different between the community version or the Community Edition and the intellig ultimate edition and these differential changes you cannot do with the Community Edition uh they're only available in intelligent idea altimate right okay so what you would do is you would go ahead you can know you can you know do as much Java write as much Java as you right uh as you want and the last minute you just sync with the database with for example the dev database or whatever have you and you'll get the you'll get the incremental change let me just delete that file uh and maybe again it works with uh liquid base it works also by the way if you just write a new uh SQL file if you say you're not even using um I don't know fly or liquid base you can literally just put you know these diff ddls into a good old SQL file that also works as well so um as always jpa body doesn't force you into a specific way but rather Tres and work with every tool technology framework language out there that you might be working with now while we're here there's just one thing I want to mention I'm not going to show it but what you could effectively do it would be super cool I thought if you could say for example hey um my current state is my model so it's my entities and then you compare this state with the model from a different branch for example not go against a DB but maybe even go against the main branch or some other you know stable Branch to compare it with there is no such Branch selector but what you can do is actually you can take a snapshot a snapshot is a specific action uh you can just you know execute uh in in in intell idea where it says take a snapshot of um sorry with jpa body take a snapshot of my model and you could do that in a different branch and then come back right and compare what you currently have against that snapshot file I just wanted to mention it I'm not going to show it to because I don't want to switch branches now with with this you know branch in in the works whatever but you can effectively effectively also compare snapshots of entities against each other all right that is um the way of me being Java first programmer so for example what I also have in my application properties file I you know drop and recreate the schema now on on every um on every startup and uh right I I don't even need to to to to talk about that anymore because mentally I was already in the second way of we have Java first and then we have database first so what if H that was quite the cut uh what if we have um I want to go the other way so instead of you know adding you know these entity sorry the attributes first in my entities I want to add the fields first in my database so first for example I could go here to my media uh column and let me just once by the way um just quickly rerun my um my application so the database tables get recreated right that's why I wanted to show you the application properties file in the first place do I still ah the migration SQL file let me just see what we have here error creating be ah right I need to uncomment flyware also as always what I'm I'm trying to do is I'm not trying to give you a perfect uh run through where there's no issues along the way rather I'm like to show stuff uh the way you would encountered in real life so that you might see the odd issue you know arriving so let's just quickly you know boot up the application uh again so that my database tables are in sync right and if I refresh my database here now you can see here is my uh media table here is my user table right that's what I wanted to show you now for whatever reason um I'm switching development Styles and I'm saying well uh I just want to add a new column here in the database first and uh what could we have um I don't know uh let's just put an expires database column here an INT doesn't make any sense but it doesn't Al also doesn't matter um so we have our media uh table which is added a new column and that column is not available here in my media entity right so I can't see it here so I would need to have a field gets and sets again don't worry about it what you can do is um and this time I'm going through the toolbar let's add a new attribute and let's say I want to add an attribute from the database right so you just click from theb again what you want to do is you want to um reload your database schema um and oh let's see if it pops up that is actually a tiny bug let me just oh I was hoping because I had that also in preparation uh you'll have it's a bit unfortunate now um that you cannot see it let me just try once more but I had that hiccup in a test run and there was a caching issue and I had to delete a cache which is very unfortunate I'll try it once more I'll say from theb and unfortunately you should see it here under the columns right because you see all the map columns and then here you should see the field expires and then you could easily sync back the changes but unfortunately I think maybe with my specific version there is a tiny bug there was a tiny bug so um you'll just have to believe me that the field would be there and I could sync back the changes sorry about that but that's how you would go about it right so in that case even though you didn't see it the sync back from the database to The Entity actually also works or should work most of the time and if not by the way our developers are probably in the back already fixing it uh once they see it so it should work by the time you're trying this out last but not least um something which I didn't show you it's not just about um you know syncing tiny attributes for example or single attributes back uh what you also could do is effectively uh invoke con action where you say hey I want to create essentially all from all database tables I want to create entities right so if you did the whole reverse engineering FL blow you can also invoke the action this very specific action to go from database table to entity at the moment I can't see any entities here because I already have entities uh for all my database tables so everything is in sync but if it wasn't in sync jpa body would tell me about it and I could do the Full Table reverse engineering which is also very cool so to some things up here in the second block what we had is um doesn't matter if you're Java first doesn't matter if your database first what you can do with jpa body uh either sync the database from your entities uh through these differential changes or get the changes from the database and put them into your Java entities as well back again second condition uh the second big conceptual block if anyone still remembers the first conceptual block uh kudos to you I'll send them up at the back uh at the at the very end again but now it's time to have a look at the third big conceptual block because so far we've only been talking about entities and you know mappings and liquid based Flyway blah blah blah at some point what you do usually in a project you have a rest controller and I'm just going to call it media rest controller here I'm just going to quickly give it the rest controller annotation and you'll have a method which is going to be a g mapping for example because you want um the user to retrieve all media H Medias or media all media which is in the database right so you're going to have a method which looks a bit like that and um here you're just going to return a list for example or stream or collection whatever have you of media note that I wrote object here the question is why did I wrote object here because usually you don't return your entities the full entities you return dto and not only that we only wrote the controller now but we also need a repository at least if you're using uh spring data for example it's common practice to have for every entity a repository and by the way you could check out my uh my my live stream with the creator of hibernate Gavin King uh last month uh about his views on on you know having these repositories or if there's Alternatives but for now most projects um use that reposit pattern so we also need a repository with a query we need a dto we need mappers uh we need all that custom code and actually I don't want to write that custom code and now let's see what um jpa buddy gives me because what I can do is I can just start typing media I did it here with an uppercase M and um so to reference the type my media entity and I get a couple of cool autoc completions here for example let's say I want to write a new media fine query because I want to return a colle collection of media and here in the autocomplete I can see hey um yeah let's do a find and I create a repository class and a method for you well let's let's try it out what happens so I just clicked enter and then jpa body tells me hey but you need a new spring data repository for your entity because there is none yet I'm going to call it media repository yeah then good luck in you know whatever finding the right repository here jpa repository list CR repository I'm just going to go with the default I'm going to put it into a specific package that's fine I'm just going to go with the default uh I'm just going to click okay now let's see um you could say hey um do I want to do a find all or do I want to do a find buy no I want to do do a custom find do I now want to find one instance so just one tiny media object or do I want to find a collection I want to find a collection and again we're back in my visual query designer where it says hey do you want to return a list a set a collection I'm just going to go with the list here uh we want to return a list of media and uh the query conditions I'm just going to repeat them uh from from from early on so file name for example starts with ignore C and what did we have creation date right is less than something I'm just going to go okay and then I suddenly get that perfectly spelled out uh spring data uh method and I always mix these up or mess these up rather so find by file name starts with ignore case and creation date less than I'm just going to put a bogus file name in here so file name and some local daytime uh local daytime now for for example example and um that returns me that just created a new repository with that method and I had I didn't have to Fumble around now we that returns me a list of media but remember I said hey I want to have a list of dto so I'll just go dot again and I'll find a map 2 action I'll I'll just click it now the thing is there's a couple of libraries out there that let you I mean you could write custom code which is fine which you can also do here in jpa body so custom Java code to map between entity and and and a dto or you could use a library or framework like mapstruct which I'm using here or model mapper again multiple choices whichever you're using in your project jpa body supports it I'm going to go with mapstruct here um I want to um create a map between media and a dto which doesn't yet exist some just going to quickly create it again I see a new window here says hey let's create a new dto I'm going to call it media dto it should be a Java record and it has let's say two Fields it has hash and hash and file name I'm just going to go okay yeah and if you know mapstruct or if you don't know mapstruct you need to have a mapping interface uh it's again so a bit a tiny bit of Bo play code to be able to map between these two again it doesn't exist yet uh so just let jpa body create it for me a so-called media mapper and then jpa body at the end of the day asked me hey um should I also maybe just because at the end of the day we have uh a list of media coming back how should I convert that to a list of media dto should I just use stream. map or specific mappa method no I'm just happy with stream. map I'm going to click okay now let's see what happened let me just here convert that like so as you can see is we get um the list of media back and we map every media object we get back with the media mapper to a dto and at the end of the day return returned as a list and that is what I mentioned actually now I can you know call it here media dto and maybe I'll just show you the classes just quickly media dto is just a record as a hash and a file name that got created the media repository you talked about earlier also just got created it's just a a good old um spring data repository that's here um the media mappa class was created and mapstruct by the way um works with an annotation processor so once I start compiling the project and that hopefully works I'll I'll automatically get a um an implementation created for this interface right here it is where you can see once we pass in uh Med object we just we just create a new media dto with that Java code that was automatically generate generated for me and I didn't have to do anything I just went into my uh controller I started out with a type and I said media repository dot created a new repository or reused an existing one created a method uh created a dto created a d dto mapper wrapped everything up in in working Java code and that is a very huge huge huge relief whenever it comes to working with entities and spring data at least in my world right okay so I showed you this let's show you a couple tiny things more uh around that so you've seen it once again I could show you 10,000 uh features just a couple of them that you might find uh helpful when I go to my repository some people by the way myself included uh have sometimes I hate these long method names and they have to be perfect and then they have to if there's an error you boot up your application you get the an error message blah blah blah you could also just Alt Enter the method name and say extract JP jpql query and configure I'll tell you what happens now we can shorten the method name so we could just say for example uh this method has the great name of ABC now right clean code and we want to use parameters let's click okay what happened uh jpa body renamed the method it um created a jpq sorry an hql query or jpql query in that case put it into the query annotation and uh that's it yeah you just cleaned up the code a tiny bit uh you have the the hql um and you don't have to you know rely on the method name um again the spring data method name it's just these tiny help features that are available at every place where you can you could just try it out Alt Enter on you know repository methods all enter on the entities wherever you have something that has to do with entities DDOS repositories In Case by the way there's something else which I find quite cool I have my media entity at the moment and we have one dto and um imagine I had another dto so for example what I could do is I could say hey let me just quickly create new dto with the sensible name of media D2 and for whatever reason it has file name and creation date right it uses the same mppa class let's just quickly create it right and uh so here we go so uh this is Media doto2 you can see it has a file name a creation date uh same with the media dto it has hash file name that's the one we created earlier sooner or later at some point in your project there comes to stage where for example you went into your media entity and said hey I have a new field that field is called private string um I don't know author for example we have gets and sets and by the way did you just see me add this well I think with local with these basic types I was quick enough to do it myself I could have also done it with the with the with the panel or with one of the actions with the available actions um to be fair so now I have the author a new author field and I want the author to end up in my dto now again do I need to remember my dto do I need to remember my field and add this manually to every single dto no I don't have to again what I can do is I can um use a specific jpa Body Action which says add attributes to dto jpa body tries to keep track of the dto in my project I'll tell you how in a second and you can see here's a window where it says hey I have two dto a media dto and media D2 they have these fields hash and file name and they have file name and creation date and now they also want an author and another author um field I just click okay and suddenly my dto have that author field and if I REM named that let me just try that now um I'm just going to give it a new name so authors for whatever reason I'll just click okay um that is also named in my dto so your entity and the dto are actually in sync ma matters a lot if for example you change a field name and then something breaks and now you don't have to worry about that stuff anymore now you might be wondering how does that linking work between these the entities and dto um the linking Works uh two ways simple algorithm if you have um classes which are called media dto for example then well we we pick it up and say well it looks like it's going to be a dto for your media entity but there's also this Java do comment and that Java do comment in any case you could you know rename that class to anything you like as long as you have the Java doc comment uh the entities and the dto are linked and by the way you can create dtos not just for entities but literally for any object uh that you have or for any class rather uh you have lying around in your project now uh what else do we have let me just have a quick look because I think I could be talking about yes we want to use spring data projections but I'm not going to worry about that for now uh because as we saw repositories we saw all all that stuff you could do I think for the third block uh that already is kind of good to good to go uh good to go uh in terms of we had the coding assistant I mentioned at the very beginning with Mala where all the boiler plate again uh repetition repositories dto um finer methods not just finer methods but every repository method um everything basically can be created out of the box with just a couple of keystrokes and a couple of dialog Windows what I didn't show you is a ton of things uh for example as I mentioned at the beginning at the moment we have uh no I didn't mention that we created everything as Java classes if it was a cotlin project you could actually also switch to creating cotland classes and cotland entities if and I'm not trying to get into that war if you had lombok on your class path you could also enable all your entities or create your entities uh with Lumbo specific annotations I know some people hate it some people don't some people use it again jpa Budd you know works with uh all of these uh languages as mentioned Java cotlin um tools let's call tool like lombok I said liquid two based Flyway pure SQL scripts uh with spring data with different um uh dto libraries or mapping libraries map struct model mapper just keep that in mind everything you might be be be be using is probably supported last but not least the topic which hopefully I can just quickly show you um is there are these you know a ton of inspections and hints and you know warnings for example when an mapping is inefficient and you could use a better annotation and whatever but I'm not going to show that to you uh most of the stuff you'll just have to explore for yourself I just wanted to show you one thing and I'm just gonna boot up the application now um and um with the hibernate or with the jpa ddl state set to validate meaning now I don't drop my database schema on application startup but I actually just validate that my database schema matches my entities and I just wanted to show off another smart feature one of the many smart features that jpa body has because jpa body actually um scans also the uh the stack traces here in your log and you can see schema validation missing column authors in table media and once you click it where you can see we can generate you know the ddl by entities uh where we can again say hey please generate me the SQL scripts uh that I need to have that specific um uh the author's table available in my uh sorry the author column available in my media table super cool um that works with stack traces uh there's also other features where I'll just give you the hint uh no actually I don't give you the hint what you need to do is you need to go on to the jpa body website later on I'm going to show it to you in a second and have a look at the documentation in the video videos there's a ton of videos about all the jpa body features out there that you might find useful now I'm nearing towards the end of what I wanted to show you I'm happy if you just take away that jpa Budd try it out tomorrow in your project try it out uh where for example you want to you know change a mapping or you maybe want to create a new repository method that I'm already happy and other than that if you remember just a couple of features I showed you in this webinar now I'm also happy and you can also by the way as always and I think you have been asking a ton of questions already um in the in the chat and let's maybe see if there are any uh outstanding questions left for our webinar uh in the last 10 minutes uh that I or Andre can help answer let's see Andre can you come on screen and help me out maybe or actually tell me about the state of the questions in the channel because I'm not sure I I was just literally babbling now for 50 minutes okay thank you for the awesome uh Speech Marco it was great it was great presentation uh yeah basically uh I think that all the questions are answered Andre uh before you both start answering the question let me uh quickly add um a link to the feedback for the session everyone is watching uh this session please submit your feedback I'm also posting a link on um the chat uh here so that uh so that we know what you feel about the session and we could improve our sessions in the future as well now I will take this off and I'll let you answer the questions of course myel great session yes thank you thank you very much so uh the only question that has remains unanswered is regarding the the uh reverse engineering from a foreign account for foreign schema in Oracle and I don't have Oracle right now at my uh in my do container but I would suggest to create two links and um import data from from the another link so uh Malik can you share my screen please yes so bringing up your yes now your screen is on the so a GPA body can work with different database connections and I have uh in my ID two database connections one is for pet clinic and another one is for postre database and let's assume that I want to import test table uh data into my uh application into my entity so uh GPA body can import data from foreign connections so basically what I have done I I have created two connections one for pet clinic and one for post and when I say I want to create a new JP entity from the database I can select a connection from here and you see if I select postre I can see my my test table and I can import it into my application so yeah I just need to create this this uh table so this is basically it uh so if you have additional questions regarding importing data or working with multiple data sources from the spring boot application please let us know in in in the ticket but as for the import uh GP body can can do everything for you and even more it can just generate additional columns for for you if you forget something in your in your uh in your application so basically that's it hope I answered the question and you can just reuse those multiple connection ability to import data from different schemas and use them in your application thank you Mal thanks yeah okay so um thanks for that Andre I'm removing your screen from the stream let me know if you want me to um add it to the stream again so um I see that you've already answered all the other questions uh so if anyone wants to add ask followup questions please do that now because if you don't get uh more questions I would close the stream and um a quick question Andre um I know you would be getting this question often uh about using custom type mapping and hibernate types library from Vlad because I know a lot of people follow uh him yeah so so does JP body already support that yeah we do support for hibernate types actually and we if you have it in class path we can detect those types and suggest those data types in in our in our Wizards so yeah we do support it and I I just want to add I Was Myself surprised I mean you saw it in in the in the presentation with how many libraries and Frameworks jpa body works with together it is surprising so uh uh yeah just wanted to add that once more absolutely and and another question if you are good to answer Andrew because we do have a couple of minutes uh so what about the entity graphs oh yeah this is the feature I think it it was the most expected feature in the GPA specification entity graphs and yeah we have a nice visual wizard for entity graphs and as soon as you click on your uh GPA repository method you can just in the pallette you can just create the entity graph that you want to use in your query so yeah right so so you just mentioned that one of the most uh demanded features so do you already have a road map for the next set of features that are coming in so we basically uh have a road map for supporting hibernate 6 even better than we we do have now so we probably add more inspections regard which are hiber net 6 specific because there were some changes there and uh for example U the uh graph routing is is a bit different than hibernate six so we are going to um add the warning if you are usually using suboptimal suboptimal queries in the uh in the uh jpa code so yeah we we do we do have the road thank you so much uh I don't think we have more questions we do just a moment as soon as we say Okay so the thank you messages so let me show some of those messages so we have the session was really helpful uh thank you guys Marco is totally the code I don't know if the greatest of all the greatest of all time I don't know if I'm the greatest of all time but thank you I I'll take I'll take it as a compliment so uh people are looking forward to watch more of your content Marco uh Ricardo says really awesome um BR says really a great tool and there were a couple uh top as well which I'm missing or which I didn't mark so um thank you so much um I think that was a great session Marco and thank you so much Andre for answering all the questions and I missed saying that Andre is working with jet PRS and he develops a lot of of tools and plugins and a lot of other things as well so thank you Andre thank you Marco and of course course thank you very much thank you thank you for watching everyone and uh have have a nice day we we still need closing comments from you we can't close the stream now oh we can't we can't close the stream now uh what should I okay closing comments now it was a pleasure hopefully you learned something I have unfortunately I have no equivalent to to the Marco codes at the end of a session uh but I'll see you all in the next session I'm very looking forward to it and thank you Andre for you for answering the questions thank you Mala for for hosting the thing and um it's been a pleasure what should I say thank you so much um Andre any closing comments from you thanks very much for attending the uh attend the session thank you Marco for great presentation and yeah looking forward for uh you using our product thanks thank you so much thanks everyone watching the session it was great everyone joined us today and I hope you learn a lot of things from this session and uh stay tuned for our next episode which would be uh in December first week I believe and that's going to be a good one a great one so so keep uh stay tuned and until next time bye-bye bye bye bye hello again
Info
Channel: IntelliJ IDEA, a JetBrains IDE
Views: 11,852
Rating: undefined out of 5
Keywords: IntelliJ IDEA, webinar, jpa buddy, jpa, jpa data model, spring, flyway, Liquibase
Id: TpD6bT9M1CE
Channel Id: undefined
Length: 58min 42sec (3522 seconds)
Published: Thu Nov 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.