The Java Persistence API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects/classes and a relational database. It is part of the EJB 3.0 specification and is the industry standard approach for Object to Relational Mapping (ORM).
Questions tagged [jpa]
60 questions
22
votes
5 answers
Is staying implementation agnostic really worth it?
I have a project that I'm working on currently using Tomcat, Spring 4, Spring Security, MySQL, and JPA w/ Hibernate.
I picked JPA from the standpoint that it's suppose to make swapping out the underlying implementation of ORM providers seamless, or…

Jazzepi
- 494
- 2
- 4
- 10
22
votes
4 answers
How can I use unit tests and TDD to test an app that relies mostly on database CRUD operations?
At work, one of my projects is mostly about taking data passed in from an external client and persisting it in a database. It's a Java enterprise app using JPA and most of our logic revolves around CRUD operations.
The majority of our bugs…

Daniel Kaplan
- 6,776
- 5
- 32
- 46
16
votes
2 answers
Entity to DTO Usage
Been trying to come up with a flow for a basic tiered web application, and have been reading conflicting information online. What I'm trying to figure out is if there is an advantage to still using DTO objects from your DAO to Service layer through…

dardo
- 355
- 1
- 2
- 11
9
votes
1 answer
IntelliJ with Maven compilation
I have a project that needs Hibernate jars.
I added them as dependencies in the pom.xml and Maven compiles my project well.
However, in the IDE, all annotations and calls to Hibernate API are marked as unresolved (red).
How could I get IntelliJ…

Mik378
- 3,838
- 7
- 33
- 60
8
votes
1 answer
ORM: runtime proxies vs bytecode instrumentation
What are the benefits of using runtime proxies with an ORM provider like Hibernate or EclipseLink compared to bytecode instrumentation/enhancement?
I know that bytecode instrumentation helps to optimize dirty checking. Because it can intercept…

Dragan Bozanovic
- 257
- 1
- 12
8
votes
1 answer
Where to put JPA annotations? Field, or getter?
version in field:
@Column(name = "SAMPLE_STRING")
private String sampleString;
public String getSampleString(){
return sampleString;
}
version in getter:
private String sampleString;
@Column(name = "SAMPLE_STRING")
public String…

CsBalazsHungary
- 1,389
- 3
- 13
- 15
6
votes
1 answer
Is this database design good? What JPA Entities should I create for this design?
I am trying my hands on JPA. For this I am thinking of using the example of a student admission process as shown in the diagram below.
Is this design good ?
Any suggestions for improvement are more than welcome.
I am also confused about what Entity…

Nils
- 207
- 1
- 5
6
votes
3 answers
When Business Object fields should not exactly reflect database columns
Main advantage with Hibernate annotations is the fact that a simple POJO (also called a Business Object the most of time) can become persistent through Hibernate annotations (or actually JPA) .
In the scenario where our conceptual domain model…

Mik378
- 3,838
- 7
- 33
- 60
4
votes
3 answers
Allowing users to add their own custom fields in a Spring MVC Hibernate application - What's an ideal approach?
We all may have seen applications like JIRA, or many CRM or other applications that allow its users to define their own custom fields to an entity, and do a variety of stuff with it, like making them mandatory, validate their values and so on.
I…

Sriram Sridharan
- 149
- 4
4
votes
2 answers
What's the correct approach to DAO layer in presence of ORM framework
I'm using JPA/Hibernate but probably it doesn't limit question.
Currently I'm writing my data access code in my web controller classes. Thanks to JPA, in most cases this code is very simple, basically simple query with trivial setup.
I tried to move…

vbezhenar
- 141
- 4
3
votes
3 answers
Best practices for retrieving data scattered over multiple tables
In the company I work with, we have a 3-layer architecture in our micro-services and the flow is like this:
Repository/DAO (entity) => Service (entity) => Controller (dto)
At the Controller level we map our entities to DTOs,
Now I am working on a…

Hayi
- 47
- 1
- 5
3
votes
2 answers
Using Map to pass query parameters in DAO
It's very common see a generic's DAO implementation like this:
public List getResultList(String namedQuery, Map parameters) {
Query query = entityManager.createNamedQuery(namedQuery);
parameters.entrySet().forEach(e ->…

Rodrigo Menezes
- 340
- 1
- 4
- 10
3
votes
2 answers
Problem related to optimistic locking performance
I'm designing a system that like the majority of social related application has posts, people can like the posts and comment on them.
And also like the majority of the applications the users can see how many like/comments a post got.
The problem is…

Lucas Piske
- 371
- 3
- 10
3
votes
1 answer
Calling repository inside a mapper
Is it bad practice to autowire and call a repository from within a mapper class? I have a mapper class that maps a model to an entity for JPA. In order to keep repository calls within my service, it requires additional loops/code in order to get…

MeesterMarcus
- 177
- 5
3
votes
0 answers
Are Remote EJBs the right way to go?
I am planning to remodel my current application and I am not sure if this is the right approach.
Currently
I have a Java Enterprise server application with 3 web-applications and an ejb-application which handles the database (JPA with EJB-Facades).…

GameDroids
- 131
- 2