Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed yesterday.
Improve this question
I understand that there are so many ways we can get data from the Db, one is using JPA or Typed/Named Query.
Wish to know on an Enterprise level do we use JpaRepository or custom repository and if custom what exactly do we use to fetch data is it Stream API or Criteria API or something else .
I have tried to use JpaRepository, getById() and also Stream API filter
I have been doing enterprise programming for a long time and the best choice for me was JPA because JPA allows you to avoid writing DML in the database specific dialect of SQL. JPA allows you to load and save Java objects without any DML language at all. When you do need to perform queries JPQL allows you to express the queries in terms of the Java entities rather than the (native) SQL tables and columns.
Also many helpful annotations like #DynamicUpdate and #DynamicInsert help ORM to create more efficient queries.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am currently working on a project built using the spring framework. We are using stored procedures instead of Hibernate queries
What are the advantages of using Stored procedures instead of using either Hibernate methods or queries in DAO classes?
Depending on what you are doing in the stored procedures, it might be better latency-wise to use stored procedures to avoid network round trips for successive database calls. I don't know if MariaDB supports this, but I think some databases support pre-compiling stored procedures to reduce the latency even further.
Having said that, if you use the advanced SQL features of your database (recursive CTEs, window functions, anonymous blocks), you should be able to get a very similar performance. IMO it only makes sense to use stored procedures if they are called by multiple applications that can't share code.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
as i know for Querying from Persistence we have below options
Criteria Query
QueryDsl e.t.c.
i am using queryDSL
so is that good approach? or any other library that i can use
Criteria API is a bit tricky/complicated compared to Query DSL. So, I prefer Query DSL.
Reasons:
Type safety is the core principle of Querydsl and one of the best reasons to prefer it.
Compact implementation.
More like JPQL syntax.
Refer to the Query DSL advantages doc for details.
QueryDSL is
more similar to SQL so it might be easier to learn for people who have not touched Criteria before.
more compact
more type-safety
closer to JPQL syntax
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I read about the runtime query builder querydsl. But I could not figure out the best cases or examples, where querydsl is most useful. If somebody can explain, it would be really good.
Querydsl helps you to get rid of hard-coded queries and provides a library that encapsulates the functionality of SQL through the hierarchy of corresponding types and interfaces.
It is a better practice to code your queries using interfaces and parametrize the calls.
You will be able to auto-test your changes during the build time using JUnits.
The above makes querying more robust and improves the maintainability of your codebase.
QueryDSL is type-safe queries purely in Java, no strings involved.
repository.findAll(QProduct.product.owner.name.startsWith("Hello"));
So when is it a good idea to use it?
Whenever you need to query from a database that is supported by QueryDSL, of course. Why use SQL when you can use QueryDSL?
If you need to create dynamic database queries, you should use Querydsl.
The pros of using Querydsl are:
It supports dynamic queries.
It has a very clean API. In other words, it is easy to create complex
queries with Querydsl, and the query generation code is easy to read.
It also supports JDO, Lucene, and MongoDB.
The only “problem” of Querydsl is that it isn’t the standard way to create dynamic queries with the Java Persistence API.
Quite fine tutorial with very good explanation you can find here.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I mean wizards such as JPA Tools in Eclipse which can help me generate tables from entities or entities from tables.
Or is it best practice to do everything manually?
These types of wizards are incredibly useful, but they rarely get everything 100% correct. I suggest using them to create the initial schema but then do any fine tuning yourself and check the result carefully.
Often the quality of the schema created depends greatly on the detail that you supply in your annotations. The better the annotations the more likely your schema is generated correctly (for example make sure you specify the length attribute against String columns to ensure they are sized correctly in the database).
Generating table from entities is ok. If you have to do it the other way around (generating entities from table), it's best to do it manually.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Are there any differences, pros/cons of using any of the hibernate persistence mechanisms
Native API & hbm.xml files
Annotations
Java Persistence API (JPA)
Envers
Thanks.
You are mixing your metaphors here
Native API & hbm.xml are used by Hibernate to read and write to a database. They convert objects to a relational tables
Annotations is a way of specifying in a class the various relationships between objects/table. This can be used instead of hbm.xml
JPA is a framework for implementing O-R and the bits around it. You can use JPA with Hibernate.
Envers I dont know much about but I belive is an auditing module within Hibernate
I would recommend keeping things as generic as possible so that if Hibernate does not meet your needs to you can use EclipseLink or something else. If you tie yourself down to hibernate then it will be very hard to move if you have problems (saying that I used hibernate and never had reasons to move.... yet ;) )
I would recommend looking up more details on each of these and them coming back with specific questions
Hibernate Vs JPA Semantics:
We use JPA semantics throughout our projects which is similar to interface based implementation where JPA specification is like interface definition and Hibernate is the provider that implements the specification.
Annotations Vs hbm.xml:
We decided to use annotations instead of specifying the entity definition in XML files to make correlation between domain object and database objects easier and well connected.