Hibernate provides reference fetching (using 'getReference()' or similar methods) to access entities without loading them into memory. This is useful for lazy-loaded relationships where you need to access a related entity without triggering the database query. Reference fetching saves memory and improves performance when dealing with large object graphs. Hibernate automatically handles orphan removal when child entities are removed from parent entities, simplifying cleanup operations.
Inmersión profunda
Prerrequisito
- No hay datos disponibles.
Próximos pasos
- No hay datos disponibles.
Inmersión profunda
The Persistence Heavyweight Championship: JPA vs. jOOQ by Pasha Finkelshteyn / Catherine EdelveisIndexado:
Spring I/O 2026 - 14-15 April, Barcelona Slides: https://speakerdeck.com/cat_edelveis/the-persistence-heavyweight-championship-jpa-vs-jooq “In the blue corner: the undisputed heavyweight industry standard, the king of the ORMs, weighing in with a decade of dominance and millions of Stack Overflow answers… JPA! In the red corner: the lean, type-safe challenger, the Sultan of SQL, the elite defender of the database… jOOQ!” This session isn’t just a talk; it’s a technical title fight. We’re going glove-to-glove on the issues that matter: the N+1 knockout, the “Criteria API” clinch, the power of code generation, and raw runtime performance. After every round, the referee (the audience) will vote to decide who landed the winning blow. Who will bring home the belt, and who will be left on the canvas? Your vote decides the champion.
[music] >> What's that?
Hey, I'm Pasha. I'm Catherine. And we work for BellSoft. We are developer advocates at BellSoft and we are actually colleagues, but today And but today we are an open we are opponents in a boxing ring. Yeah, and we're in different corners of the boxing ring.
>> I'm in the blue one and she is in the red one. Obviously, I'm heavyweight, but she's a professional. So, yeah, I did boxing and he's a heavyweight, so let's see. Let's actually maybe vote who leaves with a black eye today.
>> [laughter] >> It will be me, I think, because technique always wins. Yeah, but you said that you don't get black eyes. But obviously we fight not for ourselves. We fight we champion for technologies.
Yeah.
>> mean that we love these technologies.
It's just our role, so so don't be mad at us. Don't be mad.
Be mad at them.
Yeah.
And obviously, you know what technologies are there. jOOQ and JPA.
And I'm here for jOOQ. I'm championing for jOOQ because Thank you.
Because jOOQ says that SQL is the only thing you need to know to do enterprise development.
Okay, and I am championing for JPA. I'm sure many of you have used JPA and Hibernate, so I'll get some support and some love, hopefully.
>> How many people tried JPA here?
You see? No votes. Right. I won't ask about jOOQ.
So, since it is the boxing match And it's going to be very interactive. So, we need you as our judges. All of you.
>> Yeah. Yeah, you will be our judges. We fight actually we fight for future. So, because in the next project you you're obligated to choose what you have been voting for during this match. So, please scan this QR code. It leads you to a page with where some votings appear.
Yeah. But no don't worry because this QR code will be displayed with each question, so you can scan it later if you wish. With this we are starting.
Yeah, let's go. Let's go. And round one.
Speed and ease of development. And let me just jump right in here because I I think I have a very very strong point.
So, with JPA and with Hibernate, we stay within the Java realm and Java model. We write our domain models as Java classes, POJOs.
Then we use annotations to define columns, to define connections between entities, and that's pretty much it. I like how you call it simple because I find the SQL guy I find it extremely complicated. Okay, I understand entity and table. That's the simple simple stuff. Explain me please this one-to-many cascade type all. What is cascade type all?
>> Yeah, so JPA enables you to work with the parent entity and it will automatically do something with its child entities. So, for example, there are several cascade types. There is detach, there is merge, there is persist, refresh, and delete. Five.
Five. And there's all, so six.
Six, okay. All includes all of the five.
All of the five.
>> Okay, what is persist or this merge?
>> So, yeah, persist it's when you save the parent entity, the child entities are saved automatically. Detach means that if you detach the parent entity, it's no longer the part of the session and I understand persist. It's about saving things to the database. What is detach?
Oh, detaching. You know, each transaction Hibernate has sessions, right? And these are the transactions.
So, the transaction within which we work with entities and then they are saved to the database or removed or whatever happens to them. And why would we want to detach them? Well, we would want to detach the entities if we want to for example avoid accidental updates or if you want to speed up the whole process.
So, when we want the JPA to stop watching the entity for some time.
And with this, if you detach the parent entity, the child entities are detached as well. With others, that's pretty much the same logic. So, for example, merge it means that if you update the parent entity, the children are updated or attached again to the session.
With remove well or delete in Hibernate, we Yes, Pasha, I see that you have a question, but please let me finish, right? I'm not asking anything. So, with remove we when we remove the parent entity, the children are removed. And with refresh, we pull the fresh data from the database in case the entity was updated or something happened to it within the transaction, so we can refresh it. Yes, Pasha, now you can ask your question. It's not a question, it's more of a comment. All right. Why does it have to be so complicated? You have insert, update, delete I don't know whatever. Sure, but you don't actually do that. That's what Hibernate does for you. And you have to know it and a lot of things on top of it.
>> Yeah, but you have to know what they mean. But with jOOQ and with SQL you have to actually write all that stuff yourself.
>> Okay, please continue. All right. So, then we have classes where we again work with our entities. Here we use Spring Data JPA which makes it even easier to work with JPA and Hibernate.
>> Abstraction over abstraction.
Abstraction over abstraction. I love it.
>> [laughter] >> Well, why not? Why not? Because you don't have to deal with with with regular stuff. You have you define an interface and you have some methods that are defined by default for you and you can use them in your service layer and then the SQL is generated for you.
The SQL is executed for you. The DB connection happens for you. The fetching, mapping, everything else is done for you by Hibernate under the hood. Magically.
Well, science.
Okay.
I got it.
Right. And finally, we can have queries by convention. So, it means that in the name of your method, you can actually define what Hibernate will do. So, in a way you define the query that will be executed by Hibernate. Do you think that it's a readable name of a method? Pretty much readable to me. Who who who who is agree?
Okay. So, in my opinion, it's slightly overloaded. But what happens if you need to find by supplier ID, name, and something else and order by?
We have a photo. Now we can do it.
No wait.
We can do boxing stance. We can do boxing. Yeah, okay, let's do boxing.
>> [laughter] >> All right. Okay, well. Many arguments, many or order bys and so on.
>> That is possible and the creators of all that stuff actually thought about that and Spring Data JPA documentation explicitly says that if you have three or more arguments, you should write a query. HQL, JPQL, or a native query, whatever you like.
>> And it will be just a string, right? No, it doesn't have to be a string, but we will do that in the next round. It will be. Well. Let's let's go further. Okay.
First, if all you JPA lovers love this entity so much, then jOOQ has something similar and it's called records. Records have been generated from you for you directly from database and you can can fetch this records from like this.
db.fetchOne. db is just injected for me by Spring. It's DSL context of jOOQ. I can fetch the author, set its name, set its age their name, their age, and so on. And then I can call store and it will be one update query on my author.
>> Yeah, but what's the author? What is author record? I mean >> Author record? We'll talk about it a little bit later. jOOQ generates a lot of stuff. Can generate a lot of stuff.
It is an active record. Who knows what active record is?
It's like a smart models who know things about databases. And you can change these models and they know how to save data or how to update data inside the database. It's not a popular pattern and I'm not saying you have to use it. If you like it, you can.
If you don't, this is my way. This is what I like.
First of all, readable business name of the method. Find by supplier long supplier ID. We immediately know that we will find product records by supplier ID and we don't have to put long supplier ID inside our method name.
Then we'll call DSL select from products. Products is also generated for us automatically where product supplier ID equals supplier ID.
Order by product name descending.
Fetched into product record class which is auto mapping like you do like you would do in Hibernate probably. Or we can do into product.class. It's not that important.
You had a question. Well, mostly a comment actually. Just like you. Well, that is all very well. You just write SQL. All right. But what if you have like hundreds of methods? You write SQL for each of them. Finding by ID, finding by name, so on so forth. That's just too much writing SQL.
>> I think this is true and I call it control. I don't run random things which are generated by obscure framework for me.
I know what I created. If I don't have this method, I should either think why I don't have it or just create it. Well, maybe it's like riding a donkey or a sports car. I mean, donkey is more reliable and you don't crash into the building with a donkey, right?
>> It's It also has a soul.
Which is an important thing.
>> [laughter] >> All right.
>> And here is our first judgment round.
Now, please decide who is better. I mean, not as a speaker. Oh, you're winning. Mhm. By a lens. No, really?
Who's doing that?
>> [laughter] >> Okay.
>> Oh, that's interesting. Cool. Well, okay.
Do you Are you writing down who wins every round? Oh.
Okay, let me just do that right now.
>> Yeah, we will give them like 10 seconds more because I do understand that you can jump between them all the time all the talk.
And someone does it. Thank you.
If you could just move it slightly towards Juke, I would be happy.
>> [laughter] >> Are you done?
>> Yes, I think we are. Okay, let's go further then.
JPA won.
Now, type safety.
Type safety. Uh here is I believe it is my round because Juke is all about type safety. Juke generates everything and everything is type safe.
For example, it will generate this classes with table names and field names for you. Like here, product has product ID and product name and so on. And their types are defined and you can't call something not callable. You can't I don't know. Uh count some of strings.
In SQL, you could make such a mistake.
Juke just won't uh let you do it.
Product records, you already know that they are entity-like things, active records actually, which are suitable for fetching and sourcing and updating data into the database.
There are several others. For example, product DAO, which is a enriched version of product record. It's a full-blown repository. By the way, if you like generated stuff, find by and so on, product DAO will have it. Oh, so you actually do Hibernate and Juke?
I don't I do both of them. I am a smart guy. I do a lot of stuff.
>> No, we are talking about doing something like Hibernate. Yeah, and better than Hibernate. Yes.
Uh [snorts] it gives you the whole CRUD without writing SQL. There are also POJOs. POJOs are like probably what you would use in Hibernate for DTOs. And also, you can generate this uh interfaces with the obscure naming IProduct. I honestly don't like it.
Still generate it everywhere because like to have IProduct as an argument of my functions to not care what is being supplied as an argument, product or product DAO or product record. All of them implement IProduct. Yeah, but Pasha, product and uppercase product, product DAO, product record, isn't that too much? It is. It is too much. That's why you shouldn't use them Okay.
>> until you know what you're doing.
Uh SQL is enough. You probably only need the topmost item, the generated table table names and uh field names. And obviously functions and so on, which are also generated for you.
Okay.
And this is how you would connect Juke to your project. It's just one plugin Juke code code game Maven, code game Maven. You give it one goal, generate, which you are running in generate sources phase.
And then, you give it connection to your database in test containers. You can use test containers.
Good.
>> Nice.
Uh or locally running database if you are doing it for whatever reason. And it has a lot of settings like what kind of database it is, which tables we want to include. If you use Liquibase or Flyway, you probably don't want to include the meta tables with meta information from them. What you exclude, which schema do you use, and many, many other settings including what you want to generate. If you are writing Kotlin, who is writing Kotlin here?
Okay, you can generate Juke Kotlin stuff with Juke, too. It has support for Kotlin and it is very nice. Okay.
>> Let's talk about generation for Hibernate. Does it have anything? Well, with Hibernate, that's a little bit different. But actually, I might surprise you, Pasha, What? Can you?
>> Yeah. Well, I can with a secret punch of mine. We had three rehearsals of this talk.
Can you still surprise me? Yes, I can actually punch you.
It will be surprising.
Right. Well, maybe I have a surprise for my beautiful audience here. Who has heard about Hibernate processor?
Oh, nice. Okay, then I have some goodies for you. Right, so Hibernate processor is able to generate the JPA static model. So, you can actually get this type safety like with Juke, but with Hibernate. And Hibernate processor can also validate HQL, JPQL, and the JDQL queries. And you get type safe JDQL?
Yeah, that's another kind of uh Well, nobody uses JDQL, so it's usually uh HQL or JPQL. Okay. Yeah.
Right. So, and then you get type safe everything. You get type safe criteria queries, you get entity graphs, you can get dynamic queries, and everything is type safe. And integrating Hibernate processor is much, much easier than integrating Juke. You only have to add the annotation processor path to Maven compiler plugin. And that's it, basically. And you know why?
>> You know why? You know why, Pasha? Is it so simple?
>> why, but tell me. Yeah, because Juke is not database agnostic. So, you actually have to configure everything, right, to uh make Juke know which database it works with. With Hibernate, that's not the case.
So, that's it. Yeah. You are saying that with Juke, we are doing database first approach, and with Hibernate, we are doing entity first approach, right?
>> Well, yes. Okay, fair.
>> Pretty much it. And here you can see the part of the static model uh generated by Hibernate processor. Uh product underscore. So, there is not so much product, product uppercase, lowercase, DAO, record. No, it's It's a good question. I asked it also in the previous talk.
>> No.
>> [laughter] >> Right. And then you can use that to build the query. So, for example, here we have uh list of products find by name. And then we build uh the criteria.
Say, select product where a criteria builder equals product.getProductName.
So, that's the same type safety you have out there. I kind of like it. It has its upsides.
Well, I mean, you should have a root criteria builder and criteria criteria query, whatever they are, I don't know.
But then your query actually looks fine.
Except, why do we call seek seek you select? Okay, it's like db.select. I don't understand it. Where cb.equal.
Why can't we just call product.get product name equal name? Why Why don't we do it in more SQL-ish way? In In a bit SQL-ish way, yes. Well, but that's how the criteria API was written. I mean, yes, I know, I admit it's not very beautiful, it's not perfect, but at least it works.
>> Yeah, I mean, it is type safe, that's for sure. Here I agree. And can we call, I don't know, um some native queries here? Uh in this case, yes, I think you What do you mean call here?
>> what if I want to have like a call a native database function inside this thing? Can I Can I do it? Well, you can make it with an annotation or native query, for example.
Uh and here's the example of uh dynamic query. So, for example, we have the warehouse and we want to search for products using different filters like supplier, category, and what's not. And uh here we have uh the predicate uh with the conjunction clause. So, it means that the predicate is true by default.
And then you use and operator to add new predicates if some filters are applied.
And here, for example, we see with the supplier name, if it's not null and not blank, then we join uh the uh supplier table and we add the predicate uh to the predicate.
>> a question.
Of course. Yeah, sure. What happens if we join one table two times? Like here, what if category name is not null and supplier name is not null? So, we join product two times. Oh, sorry, product supplier. You don't think You don't have to think about that. Hibernate will optimize that for you. Nice.
It's not bad. All right. And then you uh say select and use the predicate that you have built, and voila, you have the dynamic query. I mean, it looks okay-ish.
Okay.
>> Okay-ish.
Let me show you what proper dynamic query query is.
>> Oh, no, wait. I'm not finished.
Go away. No.
>> I won't go.
>> I'm not finished yet. I'm not finished yet. Uh query validation, right? So, as I said, Hibernate processor can validate queries for you. So, for example, you made a typo in your query, uh said like no such field, right? It's obviously a typo.
>> such a big typo you made. Well, maybe I was Now we're talking.
>> [laughter] >> the previous evening. Uh right. And then your code won't compile and you will get the error.
It looks nice. It's nice.
>> nice.
Except you have to write string and then wait for it to be compiled. So, let me start from the grounds, from joins we have in Juke. And in my sandbox, I think that we should just write join.
And it shouldn't be some obscure join like in criteria builder, we just call DB. Select product name from product join supplier predicate for joining where our predicate order by limit offset.
Oh, by the way, speaking about limit offset.
Did you see these ugly guys first result and max results?
Well, they could call it limit offset.
They didn't. Well, we call it limit offset here in juke because this how it's called in databases with which we work.
But, let's say if you don't Let's say you don't like this joins and you want something more transparent.
It will be something like this.
When it is a two one relation, juke has a thing called implicit joins.
And suddenly, we can call supplier right on our product. Select from product where product supplier name equal ignore case supplier name.
And look, suddenly it It almost matches SQL, but if you want just a little bit of magic, it looks slightly better than usual SQL for you. But, you can always get back to traditional way of joining things.
And Yeah. Speaking of uh dynamic queries, you can just put variable arguments inside this where.
They all we can jump to buy end and that's all. If you need or, you can concatenate them with or and it will be a call on there predicate, not a magic criteria builder, which is a nice thing. Oh, by the way, yeah. Well, actually, I like implicit join. That looks neat. But, Pasha, tell me, I have a question. So, uh is there a way to write SQL in strings with uh juke? Of course. So, not with What What are you asking? Can I use strings as a juke queries?
>> Yeah. I can. All right.
>> I can also generate queries text queries from juke. It's just one call. Can do both of them.
Question is, why would I do it? Because juke is created specifically for us not to write strings. It is created for us specifically to write type safe queries.
>> Yeah, but if there is such a feature, it might exist for some reason, right?
Nobody would ever spend time on delivering the feature that nobody actually asked for.
>> Yeah, I guess it happens when you have a client which pays you a lot of money.
And client comes to you and says, "Hey, I have this query from our DBAs and I actually don't want to rewrite it into juke. I am fine with it being written in text. Can I please use it with juke?" And you're like, "Well, whatever. Let's do it."
Now, it's your responsibility or your DBA's responsibility. This is not what I would recommend to do, but it is a possibility and I call it freedom. Okay, but if you use strings right uh queries in juke, uh can they be validated by juke? Uh kind of. So, you can define functions with juke. Let's say I need my I have my own custom function in the database which juke does juke doesn't know for whatever reason. Happened to me with post grace and try ground indexes, by the way.
So, I created my own type query with juke.
>> Okay. And I I I'm I just I defined types myself.
And from this point, I can use this query with try ground indexes. All right.
Which is nice.
Uh a little bit involved. You need to add one more method, but I would say with hibernate, it would be crazy involved, to be honest. Because using anything vendor specific from hibernate is a pain in the ass. Well, that's not this what the sound is about. And where is the vote? Okay?
So.
Let's see. Let's see. Oh, well, that was predictable. No, it wasn't. I actually I actually was not sure. Thank you, folks. [laughter] Appreciate it.
Well, I mean, do we even need to wait to wait longer? Uh just a second. Yeah, let's give them like 5 seconds, but we can just see where it is going. Oh, yeah.
Well, again, I expected it that way.
All right. 48. Yeah, so let's go further. Okay. Thank you.
Thank you all. Right. So, N plus one management. Let me read this one. Let me read it out. Oh, okay. All right. Select that performs a separate SQL select to load the data is generally termed N plus one.
Catherine. Yes. Where is this quote coming from? This quote is coming from hibernate docs.
Speaks its own.
Why?
Right. Okay, hibernate is a complex machinery, of course. I understand that.
And sometimes it does things under the hood that you may need to watch carefully. So, for example, we have fetched a list of products and we want to get their suppliers and then we iterate over each product and get uh these supplier for each product. In this case, if we use the fetch type strategy lazy, then the hibernate will happily go to the database each time it needs the supplier for the concrete product. Yes, just a second, Pasha. I'm waiting. Yeah, don't open yourself. I can just punch you in the and then it will be over. It will be over very soon. All right. So, and then there Yes, you will get the select for each product on the list.
Yes, Pasha. Question. Of course. I am a new developer just merging in the project.
I am looking at this code. Is there any way for me to understand if there is N plus one of the or if there is no N plus one in this particular piece of code?
Well, I assume that you read the documentation before implementing any technology, all right? You do? I don't.
You don't. Only losers read manuals. No, of course. Of course, Pasha.
>> [laughter] >> Right. Of course. Well, if you did read the documentation, it explicitly says that you should use the fetch type lazy instead of eager so that you don't >> one. Uh there is N plus one. Yes.
>> Uh and you don't know about that if you don't read the docs, right? And if you uh don't use the uh proper fetching strategy. But, uh with hibernate, you can use fetch type lazy or eager. With eager, you always fetch the uh child entities for the parent, which might lead you to another problem, the Cartesian product.
So, it means that you load too much data into the memory. No more Cartesian product.
If you have two tables and it will be one row of each table joined to all the rows from the other table.
That's a lot of data in the memory. So, in this case, you usually use fetch type lazy strategy, but it means that if at some point you will need the children of the entity, they will be selected one by one.
So, again, the documentation that you don't read because that's What I'm hearing from this piece of code, I can't understand until I read the code of entities, I can't understand if there is N plus one here or no. Yes, well, you Right. Okay, so you can use guardrails that are again described in the documentation. Use the lazy fetch type strategy and use the join join fetch explicitly in the query. And plus, you can use the batch size annotation for fetching children in uh batches like in 20 or 30 or whatever you decide to do. There you go. Okay.
Yeah.
Yeah, and here we have the uh example of using the join fetch, right? So, we have the order and we want the order items. And then we do the order fetch right items. And then that's it. Basically, problem solved and there's not going to be any N plus one.
You already have to know what joins are.
You already have to know what selects are, updates are. And now you also have to know what fetch is, which is not from SQL. It's pure thing from hibernate.
Well, you know, Pasha, you can ride your SQL donkey, of course. That's going to be very reliable and very hearty, right?
And it has a soul. But, we are riding here a sports car, right? It will take you from A to B very very very fast.
But, to drive a sports car, you actually have to know how to do that. Of course, if you just without sit into this beautiful Lambo, well, you might run into troubles. You know, enterprise is not about speed, actually.
It's about reliability. Yeah, so let's go Let's go to your donkey, then. Yeah, so Okay. With reliability, it's all very simple. You won't have N plus one if you don't use ORM. If you just write your queries, you see exactly how many query queries you you issue. And hibernate only creates problems. I have a hugely hugely popular post on Facebook like 10 years ago when I wrote like 10 best practices for hibernate. It was like opening for for a lot of people because no one like me reads documentation.
Okay.
What about you? We are ready to vote.
Cast your vote.
Woah.
Okay.
Okay.
Uh we are waiting for like 20 more votes.
50? Uh yeah. Well, while I just type the round three.
Yep. All right.
Okay. So, we are done here. Yeah, kind of. Well, again, that was predictable.
>> so, okay. But, even I have to admit, hibernate has its upsides. I actually read its documentation some time ago.
Long long time ago when I was a young boy.
Wow. it is about writing data. Tell us.
>> Round four. I think I know who is the winner here.
Right. So, because even Lucas Eder, the creator of juke, says that if your writing becomes complex, when you have to load the complex object graph with many entities, do a lot of stuff to that, juke will not help you. And you can see that it's written explicitly out there. Juke will not help you. This morning I told I told you this is not what he what he said and she was like will not help you at all.
>> Black and white. Black and white, folks.
Yep. All right.
So, imagine that you have to load an aggregate, an entity, a parent entity with a lot of children.
You need to make a lot of changes, update something, delete something, add something new, and then you want to commit it all to the database. That's uh >> Give us an example. I don't understand.
Of course. So, for example, we have an order. We have created an order, and then at some point we want to change this order, right?
>> Happens to me several times. So, sometimes it happens. Right.
Um so, we have the order edit request uh with several fields. Uh you don't have to use all of them, right? So, but some of them you might want to change address, add new products, remove products, change quantities, or apply uh the coupon with a discount. So, let's see how we can do that with Hibernate.
So, in this case we have the method revise order. And then we fetch the order from the repository with fetch order graph for edit. Uh I'm not sure this is the separate method. I'm not showing it to you because I already showed you before how to use fat join, right? Join fetch. Sorry.
>> Uh and this is basically it. You fetch the entity with its uh children in a right way.
And then that's it. You have your Java object and you work with that and you use the business logic written in your application, right? For example, you want to change the address, right? And though you change the address with your with the business logic. Then you want to remove some products. You do that and Hibernate will automatically uh remove the orphans, well, the uh uh rows in the database uh that no longer belong to the parents.
>> Well, this for loop will emit a lot of queries in the database.
>> No, it will not. Why? It will not. It's going to be one remove.
Why? Even if I remove five products?
Because Hibernate is watching what you're doing and uh it will not uh when it sees the for loop, it will not automatically go, "Okay, I will do that, that, and that, and that, and remove, remove, remove." It will will collect them and remove them in one batch.
>> Yeah. And after that, you can add new items again with a business logic, right? Add item, and you can even get reference to the entity without uh getting the whole entity from the database, which is very convenient.
>> more about get reference.
Please use it if you use JPA. It's like it's >> memory saver and time saver. It's just golden, right? So, we can fetch the reference, use the reference uh without fetching the whole uh object from uh the database.
Uh then we can change the quantities. We can uh add the coupon, and Hibernate all this time watches what you are doing and performs uh updates to the to children or to the parent, uh removes, deletes, right? It adds data to the database, and that's it. You don't have to do anything else, absolutely. That's it. You don't even have to call save because that is all done automatically by you. The child children are updated and saved. The parent is updated and saved.
>> You don't call save here. When does it happen? Uh automatically uh at the end of the method. All right, cool. Yeah.
And if something changes along the way in the database while you're working with the entity, you don't have to worry because there is optimistic locking that you can do with Hibernate. It means that the entities will be locked in the database and nobody can touch them or change them while you're working with them. Isn't that beautiful, Pasha?
>> I think that No, okay. Okay. I actually think that working with all the things in Java is nice.
Lucas says that juke won't help you. I disagree here.
The issue which is the issue with this glitch method? Who knows how many queries will it issue to the database?
The answer is no one. I don't know.
Katherine does know. You have to actually count. There are tools for testing Hibernate applications which will count emitted queries for you, and you can test that it was not more than, let's say, 20.
Which is useful, but you don't exactly control it. If it if it say, "Hey, too many queries."
you have to rewrite it to native. Which is fair, but you could as well write in a native like this. Oops.
So, it won't be as beautiful as in Hibernate.
>> I'll take my time. I think if they would have a chair, I would sit here, but >> Yeah, you you can take your bottle of water and and drink something. So, let's say we want to do the same thing as they. We want to update a lot of stuff.
So, with address update, it's trivial, right? It's one query. We'll just update our address.
Now, for deleting entities, it's for deleting rows, it's also very very simple. We just collect all the IDs we have to delete. If there are some, then we'll issue one query to delete them all. Some of you will tell that in is imperfect, but well, it is SQL.
In is not cached in juke, right? Uh it's not cached in database. Okay. Uh in juke juke caches nice thing. We'll We'll talk about it a little bit later.
Then, inserting is also simple.
We'll just create a huge insert to to which we will add more and more items when we go.
Insert step.values, we'll just add more values there, and then we'll call insert step.execute. It will be exactly one insert statement.
Now, for update, is it is a little bit more tricky.
Who is very familiar with SQL here?
Who understands what's written here?
You?
Cool. So, one two people.
Cool. Let me explain to all the others people because it is not trivial. For every item we have to update quantity of, we'll create a case switch in our SQL which will say, "Hey, if this is ID if this ID is one, we will have to have a quantity of two. If its ID is five, it will be quantity of seven. If its ID is 11, we'll have to have quantity of 21, and so on."
And then we'll execute one huge update with this quantity case.
And no reasonable person without thinking a lot of time wouldn't write such a request until you are broken like me, obviously, because I used to be a data engineer. This is like SQL 101 for me. But for other people, I can understand how it can be confusing.
The good thing is here is we do all the updates in one query. The bad thing again, it's uncacheable because in one query we have to update two items two item quantities. In other In other case, we need to update five item quantities.
Uncacheable. And that's a good thing.
Well, that's a lot of code, Pasha.
That's a lot of code.
>> No, it's not not not Well, no, it's just other examples how another ways to delete up there to to issue updates. For example, we can loop over items if you want and delete them by one by one.
There There are like options, and we can update coupons.
This is all trivial stuff. This This is just one more statement. Hibernate will do it for you.
>> Anyway, anyway, Pasha, there's too too much code. Why should we know about that? Why should we care about that?
>> it's a question. In my opinion, you have to know it anyways because with Hibernate there is no way you wouldn't need to write a complex query at least once. And at the moment when you need it, well, you have to know SQL.
Well, yes, of course you know have to know the SQL actually as as the groundwork. But here we're working with the persistence level, right? We Of course, juke is all about SQL, and you can do with juke everything basically that you can do with SQL, which is great. I love that. But here you are reinventing the wheel, something that is done by you for you by some technology.
You are doing that in your code. And how hard is that to maintain actually? It is simple to maintain in my in my honest opinion. But yes, you have to know SQL.
And if you don't know, well, this will be an issue for you, and this is where Hibernate would save you. But let's ask our audience what they think.
>> Okay, let's see.
Well, it's not that surprising, right?
>> No, yeah.
Well, we are roughly there. Yeah.
All right.
Okay.
Cool.
Uh we're going head to head. Yep. Yep.
Let's talk about runtime performance.
>> Runtime performance. Who cares about the performance of their persistence layer?
Mm, cool. So, many people. Why?
You're very curious.
>> Why?
Why do you care? [snorts] Why? Databases are usually the bottleneck of your application performance. Database, but not persistence layer, right?
Yeah, everyone cares about performance of database, but not persistence layer.
Yeah.
So, the database blocked and nobody else can do that. Fair. If you occupy the whole connection pool, then you're in trouble.
All right. So, performance. Right?
Hibernate, again, as I said, is a complex tool, and it gives you several features that can help you boost the performance. Right? For example, caching. There is the first-level cache and the second-level cache. With the first-level cache, the entities that you fetch are cached within the session.
Right? And with the second-level cache, the entities can be cached across several sessions within one session factory. Question. Of course. How would you use second-level cache in, you know, multi-instance application? You can do that. Uh there are tools for that. Uh from Red Hat, for example, Infinispan.
So, basically, as Red Hat uh well, develops Hibernate, it's not even the third-party tool. It's just a native tool for Hibernate.
So, you can do that. Of course, it's a little bit more complicated than just using Also, JMS. than just uh writing SQL. Yeah.
Right. Then there is the stateless session. That is actually a very curious thing because it brings you closer to JDBC. With stateless session, uh Hibernate does not watch your entities anymore, does not babysit them. So, uh with the complex query that query that we had, for example, Hibernate did it all automatically, right? It will watch the entities, update it, uh delete it, and so on and so forth. Here, it does nothing actually to uh your entities.
Uh which might be good in the case uh if you want to work with a single entity.
If uh we had the complex query like the previous one, then you might get into trouble with this one.
>> Yeah, essentially, what she's trying to say is Hibernate has a way to have author record, product record, like we have in juke from the very beginning, but it is hidden from you, and it's not trivial to use.
Right. And then there's project fetching. Uh projection fetching, sorry.
That's uh when you can you can fetch the DTOs right from uh the database with a select new clause. We in SQL [laughter] >> to yes, like juke. Yeah.
So, yeah, as I said, it's a complex tool, but it doesn't mean it's fragile, right? And it can take you to great places, and it can be hell of a ride.
But if you mess up with Hibernate, well, at least it's going to be memorable.
Great places.
>> [laughter] [snorts] >> Yeah, so it is all written in the documentation of Hibernate, right? All the ways to optimize your performance with Hibernate. Juke is the same.
Everything about optimizations in juke is written in the documentation on the one page of manual. By the way, stateless sessions are and are one page of manual, and caching is a huge chapter in manual for for Hibernate. So, it's written in the documentation of juke that it takes some time to construct juke queries. Juke queries are essentially trees, which which are then converted or rendered to SQL strings, and then it takes some time to bind values to prepared statements.
So, for first ones, if you think that they are slow, that you can try to implement caching. There are no guidelines how to do it, and because the idea is it is very fast, it is just fractions of seconds.
But if you need it, you can cache things. Uh juke queries are not thread safe, so you will you will have to care about thread safety yourself. But probably this fine. Caching strings is very simple. Question is if it's usable for you, if it's useful for you or not.
And regarding binding values to prepared statements, you should should just use connection pooling.
This is the case for all the spring developers, I believe. This is case for Hibernate. You should always use connection pooling.
>> case, we're actually on the same side.
Please use connection pooling. Yeah. And when we are speaking about performance efficiencies and so on, don't be like this guy who just decreased amount of time from six digits to three digits, not really saving any time.
Think what's important for your application. If it's actually a bottleneck, is this query rendering actually a bottleneck for your application? And if it is, then do something about it.
Okay, it's time to cast your vote. And you're you're choosing between almost no solutions >> round is already over. You can't deliver punches after the round. No, you can't.
I'm doing great right now. What are you What are you saying?
I'm But I'm close. Interesting.
Uh we need to >> Oh, nice.
>> [laughter] >> We might actually have a draw here. Oh, no.
Oh, yes.
Yeah. Cool. Thank you. Thank you, folks.
I love you. No, yeah, it's not that simple.
It's a tie. Okay, it's a tie.
>> Okay, it's a tie. Wow. Nice.
Okay. So, schema evolution and refactoring. Tell me about what happens to Hibernate when you want to change something in your database.
Well, wait a second. You might even actually want to change something in your entities because they well, your application lives, your database lives.
Things change, right? Things are updated. And Hibernate uh gives you uh domain-first code generation. So, in in the world of Hibernate, entities are first-class citizens, right? So, uh in this case, uh if we update our entities, uh Hibernate's uh static model uh can help us notice any uh troubles, issues that we have introduced. So, for example, you rename the supplier to the vendor, you regenerated the uh metamodel, and boom, the uh application won't compile. For this, I have to use metamodel generator, right? Of course. Okay, cool.
>> Yeah, right. And if something changes on the side of the database, you can use Jakarta Persistence uh validate action, and plus the integration tests to avoid compiling with mismatches. So, if you only use validate action, then the application won't start, right? So, it's a runtime check mostly. So, if you want the compile-time check when something changes on the database side, you need integration tests.
>> compile time, it's test time, but yeah, okay, I get your point. Yeah. It will compile, just tests won't pass.
>> Yeah.
So. Yeah, for juke, it is very simple.
Like everything in juke is very simple.
Just change your database in an incompatible way, and see how your application doesn't even compile. You don't need additional plugins on top of what you have. It's all in one code generation, and this is the right thing to do. It should fail. If application can't work, it shouldn't compile. So, yeah. You don't need additional plugins.
Just just see it. In my opinion, it's like two approaches.
First, by the way, who has perfect integration tests?
>> [laughter] >> Four people. So, yeah, so much for integration tests. Uh which will help you. So, yeah, you can change your database. All the people who don't have perfect integration tests, change your database, and wait or hope that entities won't go kaboom.
Or with juke, you can just change database and see application doesn't compile, then you know that you did something wrong. You made an incompatible change of database, or you just broken your code.
>> Yeah, application won't compile only if you regenerated the model, right? But does juke regenerate the model all the time?
>> That's a good question. You're supposed to run code generation every time. If you don't don't do it, it's on you. But why wouldn't you? It costs you nothing.
Okay. So, let's uh >> 2 and 1/2 minutes. Yes, we have to speed it up.
Okay.
Here, I'm not really surprised, to be honest.
I'm winning a bit.
Well, at least Well, yeah. That that I mean.
Okay. It's checking here and there, but okay, let's continue.
>> okay.
Right. And finally, the final round. Oh, we have 2 minutes. Uh speed it up. This is a championship round. Pricing and maintenance. Go, Pasha. This is my favorite part about juke. It is very a fair pricing for juke. If you use an open-source database, be it Postgres, be it, I don't know, ClickHouse, MySQL, it's free for you.
Uh if you use proprietary and free database, you're going for an express pricing. And then, more expensive database becomes, more you pay for each developer workspace. Obviously, if your company can uh afford Exadata, they can probably add couple hundred bucks on top to pay for their developers' comfort. All right.
And what is the licensing for juke? Uh it's Apache 2. Uh-huh. And are there the tests for juke?
>> Uh of course, there are tests. There is a small issue. Tests are not published.
So, if you want to fork juke, you can do it, but you will have to write your all your tests on your own.
But I have only one question for you.
Only one.
>> yeah, please.
>> Uh please answer it honestly.
Uh who maintains juke? It's company in in Switzerland nearby, which is called DataGeekery.
>> Mhm. And how many employees are there?
It's one.
One.
Yeah, so it's Lukas Eder, who is the sole maintainer and creator of the thing. He also says, just today he said in rage that so, it is a very viable business. So, if something happens to me, it's not an issue, like his wife will sell will sell the company to company which wants to maintain juke.
>> one person who maintains this project.
Ladies and gentlemen, I rest my case.
Okay. With Hibernate, that's diff- different. It was made for enterprise projects, and it's meant to stay there.
It is funded and supported for more than 20 years. It is used in more than 400,000 repositories. It has more than 600 contributors and it has so many Stack Overflow questions which are used by AI when you ask it a question. So, it means that there are so so many people who actually use Hibernate. Because you can't because you don't know how to work with Hibernate, you need so many questions on Stack Overflow.
>> Yeah, but maybe nobody actually works with it juke if there are no questions about juke, right? Continue. Okay. So, and Slice Sense is Apache 2. So, you can use it in commercial products for free with any database supported by Hibernate and if you want support, you get it from Red Hat, an established company. We are out of time. Let's quickly vote for the last time.
And I will ask to just raise your hands if you learned anything new today. About JPA or juke. Oh, nice.
>> that's our goal. Yes, exactly.
>> won.
And No, actually we have a draw.
Yes, and actually we have a draw.
>> We have a draw.
Oh, thank you.
>> [applause]
Videos Relacionados
Ubuntu Touch Q&A 190
UBports
241 views•2026-05-17
Learning k8s ep. 3 - The end of the VM
devcentral
102 views•2026-05-15
Iterators and Generators: Real Use Cases
jsmentor-uk
188 views•2026-05-17
TCS NQT Coding Questions Solution (One Shot) | TCS NQT Preparation 2027 | TCS Actual PYQ 2026
knacademy20
2K views•2026-05-17
The 4 Bit AI Training Trick
explaquiz
414 views•2026-05-19
Image to 3D World Workflow 👀
badxstudio
843 views•2026-05-16
Why Learn Algorithms in the AI Era
bitsandproofs
245 views•2026-05-17
NFA - Transition Diagram and Transition Table
nesoacademy
198 views•2026-05-19











