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).
                65 questions
            
            
            
                0
            
            votes
        
        
            
                2
            
            answers
        
        
            
                198
            
            views
        
        
            
            
            
        Keeping the impact of changes low when moving shared domain objects into a library
                    I’m refactoring a microservice project where multiple services share the same domain objects. Over time, these objects have diverged across services, causing inconsistencies.
To solve this, I plan to ...
                
            
       
        
            
                12
            
            votes
        
        
            
                4
            
            answers
        
        
            
                3k
            
            views
        
        
            
            
            
        Is the separation of a database process from the main backend process really "good practice"?
                    In our current architecture, we have a React frontend communicating with a Rust backend via REST calls. We are considering introducing a PostgreSQL database, and my colleague suggests that we should ...
                
            
       
        
            
                2
            
            votes
        
        
            
                2
            
            answers
        
        
            
                744
            
            views
        
        
            
        How should I implement data access with jpa to meet Clean Architecture/DDD
                    For the last few days I'm searching any information about compatibility of JPA and Clean Architecture/DDD. I found next ideas for decoupling application from hibernate.
Do not use @ManyToMany or @...
                
            
       
        
            
                0
            
            votes
        
        
            
                3
            
            answers
        
        
            
                383
            
            views
        
        
            
            
        Java JPA: Transaction logic in DAO vs Service
                    Being new to JPA and transaction management, I have a Spring Boot REST API application layered like this:
Controller -> Service -> DAO -> DB
I want to be agnostic from any ORM and am using ...
                
            
       
        
            
                0
            
            votes
        
        
            
                0
            
            answers
        
        
            
                155
            
            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 ...
                
            
       
        
            
                0
            
            votes
        
        
            
                1
            
            answer
        
        
            
                229
            
            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....
                
            
       
        
            
                0
            
            votes
        
        
            
                0
            
            answers
        
        
            
                584
            
            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 ...
                
            
       
        
            
                0
            
            votes
        
        
            
                1
            
            answer
        
        
            
                2k
            
            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 ...
                
            
       
        
            
                0
            
            votes
        
        
            
                1
            
            answer
        
        
            
                564
            
            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 ...
                
            
       
        
            
                2
            
            votes
        
        
            
                1
            
            answer
        
        
            
                3k
            
            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 = ...
                
            
       
        
            
                0
            
            votes
        
        
            
                3
            
            answers
        
        
            
                333
            
            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
@...
                
            
       
        
            
                4
            
            votes
        
        
            
                3
            
            answers
        
        
            
                11k
            
            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 ...
                
            
       
        
            
                -2
            
            votes
        
        
            
                1
            
            answer
        
        
            
                117
            
            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 ...
                
            
       
        
            
                3
            
            votes
        
        
            
                1
            
            answer
        
        
            
                6k
            
            views
        
        
            
            
            
        Best way to handle lazy models with mapstruct and spring transactional 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]
...
                
            
       
        
            
                2
            
            votes
        
        
            
                3
            
            answers
        
        
            
                308
            
            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 ...
                
            
       
         
         
         
        