Answer the question
In order to leave comments, you need to log in
What is the best way to use Hibernate to manipulate data in a database?
I study HIBERNATE, from what I read, I realized that three types are used to manipulate data in a database - Using regular SQL, HQL, CRITERIA. The question is, what is better to use and what is currently being used? what is better to use for CRUD operations, I read somewhere that Criteria is used only for reading from the database, I understand that it all depends on the project and what you need, but I would like to know in general terms what is better to use and in what cases? ??
for example why is it better to use Criteria a why is it better to use native SQL?
Answer the question
In order to leave comments, you need to log in
The use of native queries should be avoided. They are needed only in those rare cases when ORM capabilities are not enough, but you don’t want to abandon ORM either.
HQL is concise and simple, which allows you to quickly sketch out simple logic for working with the database. But, firstly, the correctness of the HQL query cannot be checked at the compilation stage, as well as the conformity of the types of the parameters it receives or the values returned to it, which means that the chance of the application crashing during operation increases and it becomes much harder to find errors. And, secondly, HQL is not well suited for dynamic query construction.
The Criteria API, on the contrary, is verbose and is better suited for complex logic of working with the database, but it allows you to catch errors at the compilation stage and dynamically build a query.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question