Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [jpa]

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).

Filter by
Sorted by
Tagged with
0 votes
0 answers
67 views

factory methods in JPA entity classes. anti pattern?

I started using factory methods in JPA Entity classes. But I'm not sure if it's an anti-pattern. If it is , then where do I place them instead ? A similar sample is below @Builder @Entity Class ...
kommradHomer's user avatar
0 votes
1 answer
97 views

How to persist Objects with the same parent

I am trying to build a "world" consisting of Fields for simplicity lets say there is a water and town field i created two classes @Entity @Inheritance(strategy = InheritanceType....
Tator's user avatar
  • 103
0 votes
0 answers
501 views

How to pass the entity's domain to the repository layer - clean architecture and spring JPA

According to Should I use a layer between service and repository for a clean architecture - Spring the Peristance layer is deprecated because the Repository is already an abstraction. UML solution of ...
Adri's user avatar
  • 101
0 votes
1 answer
1k views

JPA/Hibernate/Spring - What if M side of @OneToMany is not relevant for business logic?

I am writing a Spring Boot REST API using JPA, so I have my application layers consisting of controllers services repositories entities models for request, response, DTOs This question is mainly ...
dbnex14's user avatar
  • 119
0 votes
1 answer
497 views

How to define API notations for multiple tables data in the response

The question is specific to the API notation shown in the screen under the heading Table Name with the comment Joins Multiple Tables. I am using Spring Boot with JPA (Database: RDBMS) I have defined ...
ravibeli's user avatar
  • 103
2 votes
1 answer
2k views

Implementing transactional entity lockouts with Spring and JPA

Spring Boot/Java 8/MySQL here. I have a widgets table in my MySQL DB that is modeled by a JPA entity like so: @Entity @Table(name = "widgets") @Data public class Widget { @Column(name = ...
hotmeatballsoup's user avatar
0 votes
3 answers
222 views

How best to structure my Service/Repository layers when persisting a Many to One object?

I'm working on a project where I need to do CRUD operations on Book and Library objects. Naturally the relationship between Book and Library is Many to One, like so: @Entity @Getter @Setter @...
hfg124g76g1's user avatar
4 votes
3 answers
8k views

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 ...
Hayi's user avatar
  • 57
-2 votes
1 answer
92 views

Entity objects with data external to the database

I'm looking for design patterns to model (java) objects that are partially stored in a database and partially stored some other external source. In my case the external data is a whole lot of files ...
Johannes Hahn's user avatar
2 votes
1 answer
5k views

Best way to handle lazy models with mapstruct and spring transnational scope

In a typical Java Spring Web APP: we have the following layers: Model [DB Models] Repositories [where you have queries to DB] Services [Business service where you have the @Transactional annotation] ...
Youans's user avatar
  • 461
2 votes
3 answers
261 views

Pattern for syncing databases with undo option

I work on a large and old application consisting of a server and a fat client. Part of what the application does is handle a large-ish (a few 100MBs) database of frequently changing data (~a dozen ...
Johannes Hahn's user avatar
0 votes
1 answer
130 views

Normalize timestamp values or have multiple SQL queries

I have a Spring Boot application to implement a RESTful API. One of the GET requests have two query parameters: from and until (of type date). Those parameters are optional, so user-agents can send ...
user avatar
0 votes
0 answers
665 views

What's a valid use case of JPA annotation @Transient?

I'm new to JPA and Hibernate. I just saw an annotation called @Transient, which can mark a field to be non-persistent in the database. However, for the sake of "separation of concerns" ...
johnlinp's user avatar
  • 121
0 votes
1 answer
189 views

Implementing a user ID system like Discords for a web app using Java Spring, JPA, Hibernate and MySQL

I’m trying to create a web application with a forum and user profile along with other functions. However I’m thinking about how I might implement an ID for each user. The best way I’ve seen other ...
SneakyShrike's user avatar
1 vote
2 answers
2k views

How to share entity classes (JPA) among projects, where not all have DB access?

So, I have project in which several WebServices will be created (REST). For the sake of simplicity, Lets name them A, B, and C. A and B handle different tasks, but both of them consume C, which is the ...
SonneRevsson's user avatar
0 votes
1 answer
7k views

Best practice for references in DTOs and entities in Spring

Given the following architecture and frameworks: Spring Boot Application with Spring Data JPA (Hibernate is used as OR mapper); layered architecture as followed. REST layer Service layer Persistence ...
keezar's user avatar
  • 27
0 votes
1 answer
4k views

In a Spring Boot Project, would you use interfaces for entities or not?

I am currently on the decision, whether to use interfaces throughout my whole spring project or not. I scouted some open source projects and saw, that many big projects are handling that quite ...
Tom's user avatar
  • 11
0 votes
3 answers
13k views

Jpa Repository save inside a for loop

I have this requirement: Csv Upload (using opencsv) Should display if the record is inserted (if it doesn't exist in the db) or updated (if it exists). Eg.: 5 records inserted 2 records updated. ...
padmanabhanm's user avatar
2 votes
2 answers
446 views

Query with a lot of fields and joins

I have to map a legacy database with tables that have a lot of fields and relations. For example (simplified code), @Entity @Table(name = "VISIT") public class VisitEntity { @Id private ...
javlacerda's user avatar
0 votes
2 answers
2k views

performance suggestions on Aggregate root containing thousands of child entities

I understand that DDD is a design concept and implementation through ORMs are tricky but help me understand how would you solve this problem? So here is my confusion on changing on aggregates only ...
Dexters's user avatar
  • 135
1 vote
0 answers
650 views

Performance impact of JPARepository save() on a large database table with index

We have a few tables with a large amount of data and with indexes on those tables to help in faster retrieval. We are also using Spring Data JPA JpaRepository for adding data to those tables using the ...
phoenixSid's user avatar
0 votes
1 answer
449 views

In new project where you have ability to define DB and write app code, what is seen as best practice?

Good day When starting a new project and you have access to the db as well as writing the code. In this specific case it is PostgreSQL and Java EE with JPA and Hibernate. Should one: Aim to ...
Letholdrus's user avatar
2 votes
2 answers
2k views

Returning JPA Entities in Rest Api's?

Recently Ive seen so many devs working with the stack Spring/JPA and returning all these JPA entities on their rest controllers. In my opinion it's a BAD PRACTICE for several reason such: ...
carlos.hager's user avatar
3 votes
2 answers
15k views

Using Map to pass query parameters in DAO

It's very common see a generic's DAO implementation like this: public List<E> getResultList(String namedQuery, Map<String, Object> parameters) { Query query = entityManager....
Rodrigo Menezes's user avatar
2 votes
1 answer
6k views

How to represent and validate website URLs for a JPA entity

I have an application that will allow the user to enter and store (in a DB) a website URL for a company. The only requirement (as of now) beyond entry of the website URL is to validate that the URL is ...
James's user avatar
  • 285
2 votes
2 answers
1k views

Reserving database independence using Spring JPA

We are planning to use Spring Boot with JPA for our next project and I am wondering how much flexibility JPA gives in reality. If we start developing using a self-hosted PostgreSQL server and later ...
appl3r's user avatar
  • 149
0 votes
2 answers
967 views

Correct way to separate JPA with Service layer

I have two tables: area ( id int PK autoincrement code varchar ) products ( id int PK autoincrement name varchar area_id int PK to AREA ... ) The classes are persisted using eclipselink ...
Mariano L's user avatar
  • 111
1 vote
1 answer
4k views

Class Design for JPA Entities with Multiple Tables Referring to Same Business Object

I have an application that works with products from various external data sources (in DataSourceProduct) and it also maintains its own version of the product (in MasterProduct). Here's the DB schema: ...
James's user avatar
  • 285
3 votes
2 answers
129 views

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 ...
Lucas Piske's user avatar
3 votes
1 answer
2k views

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 ...
MeesterMarcus's user avatar
5 votes
5 answers
3k views

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 ...
Sriram Sridharan's user avatar
0 votes
2 answers
266 views

Any drawbacks to having very descriptive table and column names in DB tables for Java web app?

I would like to know if there are any drawbacks to having descriptive names for database tables and columns. This would be for a Java based web application, and most of the times I have seen database ...
ITWorker's user avatar
  • 137
0 votes
1 answer
2k views

Decoupled architecture between business and data layers in Spring JPA / Hibernate

I'm using Spring Boot with JPA / Hibernate and I'm trying to decouple the business layer from the data layer. I would like to be able to (relatively easily) switch from a relational database to a rdf ...
Ortomala Lokni's user avatar
3 votes
0 answers
102 views

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 ...
GameDroids's user avatar
1 vote
1 answer
854 views

auto generated web CMS for pre-existing SQL db?

What I'm looking for is a way to auto-generate a simple web-based CMS for a simple pre-existing SQL database. To be used by 'app administrators', not the general public. Something that: allows basic ...
MikaelW's user avatar
  • 651
3 votes
0 answers
39 views

Approach for querying an arbitrary set of user submitted fields and values in Spring application? Like a shopping site sidebar search?

I am working on a Spring Boot and Angular application which has a requirement to search based on any number of the available filters being applied to a list. For example, a user searches on 'Title' ...
Joe Essey's user avatar
  • 191
0 votes
1 answer
74 views

Handle publishing data across environments

I am rewriting a website that has a back-end database for containing meta-data that is displayed to the user when they enter a text code. Background: The old/existing system stored this data in XML ...
Jon Tinsman's user avatar
1 vote
1 answer
1k views

How to avoid LazyInitializationException using Hibernate and Jersey

I am working with Spring Boot + Jersey + JPA/Hibernate to build a RESTful API. The issue I am encountering right now is when I have a relationship in my JPA Entity that is lazy loaded I get a lazy ...
jkratz55's user avatar
  • 271
8 votes
1 answer
2k views

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 ...
Dragan Bozanovic's user avatar
1 vote
1 answer
2k views

DTO and JPA Version

I have DB tables representing Employees and Departments. The server side(JavaEE) contains JPA entities representing the same. The client is a standalone client and communicates with the server using ...
KayDK's user avatar
  • 11
4 votes
2 answers
2k views

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, ...
vbezhenar's user avatar
  • 141
0 votes
1 answer
1k views

Can I ditch the persistence.xml file on JBoss?

I have a Spring based app where another programmer is using JPA's persistence.xml file to define the setup of hibernate and to define the entities that are being persisted. The app is using Spring's ...
drekka's user avatar
  • 1,289
1 vote
3 answers
932 views

Limiting complexity in JPA programs Java/Hibernate

I've been working on a new application for some months now. It's my first big JPA program, and is still in the early stages. However, the complexity of my JPA object tree is becoming a growing problem....
wax_lyrical's user avatar
6 votes
1 answer
2k views

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 ...
Nils's user avatar
  • 207
2 votes
1 answer
2k views

Producing JSON objects from JPA entities in REST API

I have a REST service producing JSON and consuming JSON. A lot of this are simple CRUD operations. My initial idea was to simply use the DAOs directly in the controller: @ResponseBody() @...
CodeTower's user avatar
  • 133
22 votes
5 answers
2k views

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 ...
Jazzepi's user avatar
  • 494
8 votes
1 answer
15k views

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; @...
CsBalazsHungary's user avatar
22 votes
4 answers
3k views

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 ...
Daniel Kaplan's user avatar
1 vote
1 answer
3k views

Is Java's ElementCollection Considered a Bad Practice?

From my understanding, an ElementCollection has no primary key, is embedded with the class, and cannot be queried. This sounds pretty hefty, but it allows me the comfort of writing an enum class which ...
IAE's user avatar
  • 1,450
3 votes
1 answer
529 views

ORM: Design of the service layer

I'm currently writing a medium sized web-application and find myself asking this question many times. For example, let's say there are users, which have files (one-to-many). How should the UI access ...
incaseoftrouble's user avatar