 Well, hello and welcome to another Dev nation I'm super excited to be here today because we have a manual Bernard who's actually one of our resident experts and all things hire Renate But he's also a key Contributing member to Quarkus meaning he's one of the guys who invented this technology So he can really take us deep down this path and the next 30 minutes We have together and I actually I've known a manual now for probably about 13 solid years So he and I go way back I'm not saying that we actually like each other, but you know, we tolerate each other pretty well So it is a great pleasure. I'd like to introduce Emmanuel Bernard He's gonna take us into this presentation right now Do make sure you throw your questions into the chat tab and feel free to help everyone understand They have to refresh the browser to hear things and see things. Thank you so much. Let's go Emmanuel Thank you Yeah, I love you Thank you everyone for being here really happy to go and explain What we're gonna talk about today, which is how does Quarkus handles persistence and how can you take hibernate to the next level? Let me share my screen right there So let's do a little bit of slides and then I'll actually go most of the time Doing going to do a demo to show you everything in action So what is Quarkus first of all very quickly because so you might have already seen the previous damnation So it's literally a stack to write Java applications Nothing more nothing less But we're gonna see how it makes it in a very unique way Well, you can write just about any Java app and so on we do focus on a few things first of all We're cloud native in the sense that the We expect We make it very natural to work in a very Let's say agile Deployment platform and by that I'm thinking about a container platform like Kubernetes and and so on where you can really deploy stuff on the fly Scale to maximum levels very quickly, you know add new services and and so on and we do focus on micro services In the sense that we really work hard to make the start of time very small and the memory usage very small When you go from one money to 20 micro services Then whatever overhead you had in memory starts to pile up And that's what we wanted to address and finally several as our team mentioned start of time But service is keen into low memory usage But also start of time has to be really fast and that's what we worked on make Java Really shine into those three, you know pillar environments So caucus has four benefits the one I will really focus today is benefit number one Which is a developer Joe and I will show that in the with a persistence angle We'll see we reuse a lot of existing technology that you know and use already whether they are standards or you know De facto standards, but we make them easier to use by unifying a lot of the configuration. We've got an awesome Development mode which makes the feedback loop from right from coding to testing back to coding You know very very fast and essentially we we try to list all of the common usage and patterns and simplify them That's what panache is about and that we're gonna talk about today The benefit number two is the memory Improvement and and the startup time improvement. So I won't go into too much detail But this is a real life rest plus JPA application. If you take the Stacks that are existing out there. You're you will use probably about two over an 18 Resident set size memory not just a heap side the reason set size Which is the one that matters because that's when something like cubanities will start to kill your process when you go over Quarkus is about half that Usage total when you use it and if you go for native image compilation Which we will discuss very quickly a bit. You can get another 8x, you know a factor Start the time is really impressive as well Existing start go from, you know nine seconds to and quark is to 2.5 And if when you use the native image compilation, we're talking about tens of milliseconds for Java. That's that's unheard of Benefit number three is Right now if you have to do a reactive application That's literally a different stack different components that your classical imperative model We are unifying that with Quarkus I think there is a dev nation set up for that very specific subjects or one dive into that subject and also Quarkus is made of all of the technologies you're already using whether it be iBernet vertex rest easy and so on and so on so It's really based on the things you already know, which means you already have five years of experience with Quarkus which are always a nice benefit and That's enough talking. Let's go into the demo So I cheated a bit and I prepared the Yeah, I prepared I literally created a you know the default project with Quarkus We have a way to do that with a Maven plugin then I copied them The front end, you know resources like JavaScript and so on just because it's not the area We're gonna focus on today and I open my my idea and my my Sorry my ID and in this case, this is IntelliJ and what we have is essentially a rest easy resources that will return on when you call LO and You know, that's that's a default one. So let's get it started You know nothing fancy here except I will use the oops I will use the Quarkus Bev mod, which is the library load mod, which is the way the way you tend to write Quarkus application You star this more than you keep starting on this one So you see that the debugging is enabled so you can activate the debugger right on the fly and here the install feature CDI and rest easy for my for my application. And if I go and Literally ask my application. I've got a landing page that explains to me what to do with the Quarkus and If I go for the hello Resource then, you know, I see hello nothing fancy here. So let's go and do a Dev nation Let's say hello Dev nation and go back a refresh and I see the change right away, right? If low Dev nation live I go and refresh oops, I'm narrow Yes, he told just told me that I probably messed up my my Java syntax. Yes. I actually deleted the Tacoma here refresh and I'm back here. I didn't repackage Recompile did anything on that I went from my ID to my browser and back to my ID and everything was walking How does it work? Essentially you can see it in the source Quarkus actually when you do a browser query It will look if any file has changed in your application If they and if there is one file whether it be a Java file or a resource then it will stop the quality will compile the file Stop the Quarkus application Restart the whole Quarkus application and answer you and in this case It's in under 300 milliseconds, which means by the time you flip to the other broth the brother Do you already live and ready? So that's very very powerful and we apply the same kind of logic for tests. So if I run this test It will fail because as you say I'm as you see I'm expecting hello here So let me prepare the correction for All the tests and what the test does thanks to the ad Quarkus test is literally start the full Quarkus application And then you run the test I'm bidding the test and then you can run whatever test you you want to run in the application And because it's so fast it makes test very fast. You don't have to wait for seconds and seconds to it's like Oh, I guess I started it again Okay, but that's that's nice, but it's a very simple application what I want to actually do What I want to actually do is write a to-do application Which has I do have the front end, but I have no back end So if I do do something then actually nothing happens because there is no routes no rest and point that actually answer Do something so what I need to do is add hibernate and a few other dependencies, right? I can just delete my profile, but in this case I want to explore a bit so I can use Quarkus dot live extensions On that life, so I missed extensions Which will this mean all of the missing here Last year in a one second But it's not really a problem. So missed extension will list the list of extensions you can also see in the On the website as if you go to Quarkus IO slash extensions You will see we've got lots and lots of extensions here that essentially your your dependency so Let me speak by a little bit here and by Adding the extensions that we are interested in today So as you can see there is a JBC Postgres driver. There is hibernatorium with panache We can I mentioned that a bit later on hibernate validator and the jizz on binding for rest easy and when I do When I do this operation then it's just Does nothing Very fancy. It's literally just a bet your palm if you see IntelliJS just says hey your palm has changed. Do you want to you know on board that and that's what we're seeing We're seeing postgres panache and I'm going to validate Okay, the second step is probably to set up the database So if you're familiar with hibernate you have to go and set up a persistence dot XML If you're not so familiar with hibernate, you might not know exactly all of that Incantation and the essentially Choreography you have to do to set up that so quite to simplify is that by going into a single configuration file Of course, you can use persistence for dot XML if you really need to or want to because you want to stay In this model, but here we really try to simplify just the fact that you have data sources URL driver and so on Is enough and at entity class somewhere in your application is enough for hibernate to start properly And here I've added a couple of extra Hibernate specific properties Okay, we're ready to go. Let's define a to-do resource That to-do resource is going to be the back end of my application. So it's going to be a rest easy resource Fine as I'm showing on API and I will consume Sorry, I'll consume me a season Structures and probably produce also decent structures And the next step is say to answer to get the list of all of the resources all of the to-do in my application so it's a get and I do a list of to-do and That or Think about the flow of my of my coding, right? I just write what I want and then I'm thinking Okay, I need these to do which is my cheese on five. So I need to create it That's the Java representation of my cheese on five. So I go and create these five and because it's a relatively simple application That cheese on five will also be my entity. So I'll mark it as an entity And I can use regular hibernate and then in my resource five here. Just do an ad inject of Of the entity manager and use use it the normal way you use hibernate But here I want to use hibernate with Spanish and specifically the Active record way to do that. So active record is essentially a way to merge the entity code and Repository code of the DAO code in into one class. So Let's do that. It's a I do extend ad-panache entity, which means I inherit a few Utility methods which we will see and also the ID right by default if I want to so here I can focus on my business logic and say well to do as a title, you know, it's a regular Entity so I can make it. I can put the the JPA Annotations I can use the hibernate validator annotations or the validation annotation rather I can add more properties I'll say that To do can be completed or not completed and I say Maybe I want an order of the to do is to make priorities, right? So I'll put it here and because order is the reserve keyword Name the column something else Ordering there we go Okay, I've used public fields which might be a bit Strange to you, but it's much simpler not to have to generate the gathers and the setters and maintain that So in your to do resource, you will just use the the public fields if you say oh, but I want the subtraction I want the encapsulation you can definitely Create oh, sorry, you can definitely create your getter and setter and If they are present Well, they will be used so when you do to do in to the resource when you do to do Dot URL using the public field and the get URL will be actually Wired in your access and the reason is that Quarkus does a lot of things that build times which means it can do by code Announcements and transform the code to really be associated so you can use the getters to abstract Maybe you want to do a two lower case or something like that, right? So that's business meaning otherwise just skip the public field. That's gonna be a bit more efficient For you and I mean as caught right the way the way the code shows Not so much in you know actual performance efficiency All right, so we've got the to do up entity and when I say I merge the entity and the DO in one thing That's that's what I mean. I can return I Access my DO which also is my entity and then I've got a list of interesting features interesting operations here like list All which is what I want, but I probably want to order them So I'll also say that I want to order them by by the other fields and I can go back to my application refresh and I still see nothing which is okay. I forgot that I didn't set up any fixture to You know add data to my database, so I'll again choose a little bit to speed dial that For people not familiar with high-manage. You can create an import that XML the SQL fine There you go, and I'm just inserting that going back to the browser refresh So not only Java files are refreshed, but also resources, which is really great Too small. There you go, and I've got my application. It's read only right now if I say do something It still does nothing. So let's go and let's go and Write down these second part. So that would be a that would be a Yeah first It's gonna return a jacksores response and that's going to create my to-do and That that is the json file like the json stream that I'm receiving been transformed into a Java file. Okay Well, that's a creation. So I wanted to be transactional. I didn't show you but You go there You will see that we have started with a Lot of things like the connection pool CDI hibernator. I'm having a validator now Ayana, which is our production full transaction Stack so we can start the full transaction and still be extremely fast And also I'll use been validation so that normally the in this method That's where you will want to decide to okay. I want to validate the input to make sure somebody is not trying to poem my For my websites, but let's assume all of that has been written down as hibernate validator rules What do I need to do here? Just actually persist this object so I can do to do persist That's all you see how it flows very nicely from your code and then I just need to return the response I have created so return the creation and Probably passing back the to-do that has been created and okay If I go back a refresh Actually, I didn't have to refresh. I Can say do something and no I see that do something has been created and if I refresh is still in the database However, if I change the state the update operation, then it's lost because update has not been implemented So let me implement it Again, it's it's very much the same logic. So I won't I'll just copy paste something a bit quickly Take the call Go back here and the update is implemented as a patch operation in in in rest Then I can get going Refresh and whoops compilation error. Yes, never trust the code that you copy from somewhere Especially stack overflow. So please read it below but here we saw that there was a problem go back we refresh and No, I can mark the operation has changed and and it's it's working The other operation a bit more complex that I want to show you is the clear completed The clear completed supposed to delete from my database the completed operations Let's go and implement it. It's gonna be a delete operation again, it's gonna be transaction also, I'm gonna set that up and I'll return a response and I'll ask to say completed And here again, I'll use my deal which is also my active record pattern and say Delete completed. So here. I don't use a default method. I just want my custom method in the deal Okay, and from there, I can just say return It's a response Nobody no content rather and then please okay Then I go back to my here in my flow So I've written the floor of my method and then I can go and fix the you know the red errors and here I want to just create the method delete completed and I navigate to my My deal which is also my entity which is very convenient and then I decide to write the delete operation So I could say load all the entity and delete them But here we just use a delete query, which is something that is supported by My JPM I have on it and here I say delete completed true That sounds scary what what is this language? It's actually hql. It's jpql except we infer a lot of the context We know we are on the to do so select to do from to do where it's inferred You you can actually write it down here. You can say delete to do and so and so on But here we infer that you do it, you know everything the front Accelerates inferred up to the where close and then you can define the close and you could say completely called something But here because he calls something. It's only there is a single parameter and so first parameter We just ignore this one and you just write complete it. So it's plain hql except it's very contextualized Let me show you another one that I love. Let's say we want to write the search engine for that For that to do up. So I want to return to do's Yes, it's a Java Utilist And that's my search engine and let's say my search engine receives world We want to do pagination, right? You're a busy person. So you probably have lots of To do is to do so page here is a panache The panache type that lets you handle the pagination logic. So any important and from there Just just page just so, you know, you can create it I want a page of 25 elements or 25 by 25 and I want maybe the second page. So that's the index third page index number three and so on and so on From there, I can write the query. So my query is a bit more complex because I want to say I want the world to be like The world that I'm receiving and completed probably should be false, right? So from there I can say past the first parameter as world and Number two and here probably I want the To do is that are not completed in my search engine That's probably the one that makes more sense. Then I apply the page and I return the list and that's it. I've made a search engine and you can see how Panache queries the contextual of square you can scale much better As as you know as more parameters are coming in and so on That's all I wanted to show you on the code side Let me show you a little bit how you would make that application run in a native way So for people that have tried to use a Grail VM and compile your application natively First of all, you've seen that it fails because there is a lot of constraints But what this actually handles all of that for you and also simplified the way to Do the compilation so you just say I want to package, but I want to Compile stuff also in the native compilation, not just Java jobs and it's fix takes a while because it does a lot of Complex analysis to compile your Java application not at one time, but at real time So I'll put a notification here and in the meantime, let me actually go back to the Quarkus website There is guides that are very oriented into how do I need to do this stuff concretely and we've got a ton of those Whether they are about of duration logging SSL Web stuff data stuff messaging security cloud observability and so on and so on the one I want to dive into is the high-gnit or I'm with Spanish So as we've seen you don't have to set up a persistence that XML We can infer it from the shared Quarkus application that properties file and you can use the active record way to write an entity by extending Panache entity we do recommend you use public fields because it makes the code a bit more compact and easier to read and You you know essentially have your repository methods on on the entity itself Here's in the configuration all of those are mandatory the other one is optional You you can write the getters and the setters and do something with them and then Quarkus again will rewire the The call to dot name to dot get name inside your application So you you get the abstraction without having the We've seen that Because it's an active record pattern You've got operations on the entity itself like persist is persistent delete least all fine by ID Least which accepts a query, which is a contextualized HQL query. So it can be very compact So it's very nice. You can do counts or counts with a query and so on and so on So I'll let you go there. You can retrieve the list. You can do streaming to play with Corrections the stream the jar strings you can do pagination So you define the page size you define which page specifically you want you can move to the next page And of course when you do least we all only get those 25 results that that makes sense Also, you've got the page count which means you just say ask for page count and we do the query Give you back the list of the number of pages expected, right? So it's very easy to make those kind of classical multi, you know, search search engine Sorting we've seen sorting. Sorry. We've seen so either you put it in the query itself or you extra externalize it So it depends on your on your taste here Simplified query, I don't like to for them to be called simplified because you can make very complex query They're just contextualized so the form entity is optional the where is optional the order by is optional and we focus on the Predicates, but then you can write the form if you want to want you want to do a form with a join or anything like that It's you just pass this more complex line to the list of the right operation You can have parameters I've seen shown a little bit how it works. The one thing I wanted to mention is some people don't like to merge the entity code and the Active the the repository code. They like to keep it separated. You can no problem You just create your class you make it implement implement the Panache repository And then you put the same method that I was mentioning and of course you've got the find by ID and all of those operations as you had on the Active record entity The only additional steps you have to do is to add inject the repository in your code and then call the repository to do your operations Which means from a coding point of view I don't know should not seem but the I've been really moving state within the same code the same That methods and so on not having to go back up in my code and back down So that's the kind of thing where we're trying to do it I won't spend more of your time Just a conclusion. You've got a full stack including JPA transaction manager It starts really fast with the live reload and you can edit your stuff in the database with the library load Which is really great and we try to simplify this the simple stuff should really Sorry, the common stuff should really be made simple and that's what we've been working on as long as the very short code to test Loop that's all I wanted to say to you today. I hope there is you know a lot of questions then we can have a conversation We do have a couple questions a couple questions a manual one that I think is actually important and that is related to panache and Relationships one to many many to one. How would you handle those in a panache based application? It would just walk So panache is actually a layer on top of JPA and hibernate So everything that you're used to working in hibernate is just work So many too many one too many all of that is is is orthogonal to the whole panache aspect if your query becomes complex and Involved relations, that's what I was mentioning where in the least instead of just passing the predicate You will pass probably a more complex from clothes with joints and then the wear clothes associated to it So but just the way you use it in in hibernate So it makes it easy for the simple case but doable for the complex case. That's that's the logic We were trying to run with for panache Okay, and then just kind of a reiteration of a point Do I need to use a persistence XML with panache or can I should I what what is the strategy there? You can so if you're very much into keeping your application standard go for it But if you you don't have to you don't have to do this extra ceremony Just define your data sourcing caucus and off you go So that's the recommended way to get started and if your application becomes too complex and needs a separated persistence for Not XML for complex settings, whatever then you can go and use it again Opinionated and very simple but doable for the more complex piece Okay, one last question and then we do do need to kind of wrap up here soon And that is related to migration so a lot of people, you know, that's a common question is Hey, how what does it take to migrate an existing application over to this new world? What strategies do you have and recommendations for people? So? What we've seen is so first of all we We use a lot of existing frameworks and so if you your application was using cdi and hibernate and Jaxer s and so on and so on We've seen quite a few people actually taking their applications spending half a day on it and make it making it run on Quarkus and be like re impressed by the ease ease of use on that front if you are What was the second part of the question? Well, just just overall strategies for migrating from an existing code base into Quarkus. That's all Yeah, okay, so To be fair, it's really for you know greenfield application would be the easiest way to get started If you feel like your application is already someone in the microservices front And you want to pull this stuff in a limited amount of time that the fact that we've reused all of those existing libraries And we just we don't in a new API is on new annotations We just expose the one, you know, and we make them run much much faster from a real Startup time point of view and the amount of memory we use That's all yeah, it's not magic, but it's it's getting closer But I really do love the point you made we have seen a number of people out in the social media world right base They have told us they were able to migrate an existing microservice right over leverage the Quarkus capabilities to go native to get faster, you know smaller faster and of course native compilation, which is so cool Well, we are out of time for today a couple other comments there edson yinaga saying we I recommend fly way for database migration So he's trying to make that point there. Yeah For it. Yeah, so maybe next time you gotta add to the demo Yeah, and I love the time. I love the hibernate search reference by the way I thought that was cool. That was super cool. I haven't seen that one yet Well, thank you all for your time today We do need to get out of here because we do have a 30 minute time limit a manual awesome job on that demonstration Several people did catch the typo with the list dash extensions. So it was it was close Yeah, no worries though. It all worked out great Yeah, exactly so, you know, you guys know it was live today look for the recording and an email that comes out from our marketing team If not, do go to our our standard channel on YouTube and you'll see all the recordings there as well You can also go to the playlist. I run on my channel So you will have access to recording as soon as possible, but again, thank you all for your time. Thank you Emanuel You're welcome and goodbye everyone