Questions tagged [hibernate]

An object-relational mapping (ORM) framework for the Java programming language.

Filter by
Sorted by
Tagged with
0 votes
3 answers
129 views

Optimizing writes over the same entity in relational DB

I am developing a micro service that saves votes to a relational database. I have a use case with an entity that represents an aggregation of votes. I receive events from voters saying that they vote ...
jesantana's user avatar
  • 146
0 votes
1 answer
867 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
3 votes
2 answers
392 views

What to do when putting logic into the database seems to be the only option?

I am currently working on an application that models a complex business process that consists of many steps, each having a 1:n relationship with subsequent steps. The software is written Java using ...
xgb84j's user avatar
  • 149
4 votes
3 answers
6k 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
258 views

Is it a good design to have separate Hibernate entities for general user info and user password digest?

I'm developing an app with a user management system. There is a database table named user with the following columns: | Column Name | Column Type | |-----------------|-------------| | userId ...
johnlinp's user avatar
  • 121
2 votes
1 answer
4k 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
  • 441
0 votes
0 answers
434 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
154 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
0 votes
1 answer
6k 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
2 votes
1 answer
261 views

How to correctly translate UML Association, Aggregation and Composition to a Hibernate mapping?

There is a number of questions about the differences between UML Association, Aggregation and Composition out there and many many answers, some practical and some phylosofical. Here I'm asking we talk ...
AlexSC's user avatar
  • 259
0 votes
1 answer
2k views

Decouple business logic from DTO

I've to implement some Backend Webservices, which provide a given, final JSON structure, which is allready in use on the FrontEnd side. This structure doesn't match the database structure, so I have ...
user2622344's user avatar
0 votes
1 answer
851 views

Mapping bidirectional 'toMany' relation from DTO to entity

The application that I am working on has numerous ...toMany relations, e.i. class Model can have several parameters. In Unidirectional world, it is simple to manage a collection. I can clean the ...
Serafins's user avatar
  • 119
-3 votes
1 answer
2k views

What do you think about DTOs in Spring Data JPA project?

First of all, I am not a junior programmer. I'm just looking for best-practice. How do you use entities and DTOs into your Spring Data JPA projects? Assume there is our layers: Repositories (as ...
bvn13's user avatar
  • 25
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
11k 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
1 answer
356 views

Can I reduce locking for this scenario using Hibernate and H2

My Java application uses Hibernate and H2. It process music files within folders. Typically for a folder it would read the files in the folder and store each file as a Song class in database, then ...
Paul Taylor's user avatar
2 votes
2 answers
366 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
-1 votes
1 answer
353 views

DDD persistence through non-orm tools in java

So our domain model drove our database and ORMs worked for DDD implementations. Now the tables have been altered a lot and as a consequence ORM impedence is too much in our domain model to use ...
Dexters's user avatar
  • 135
2 votes
0 answers
39 views

DataBase design generated by hibernate Many to Many for MariaDB

Hi I am in middle of designing DB and Got a little bit confused about DB Design. I am Using Hibernate as ORM Tool ahd mapping between Page and Step entity in hibernate. @ManyToMany(fetch = FetchType....
ThinkTank's user avatar
  • 121
1 vote
1 answer
74 views

concept for de- and encrypting personal data in web portal

Issue: I provide a small web portal for customers with partial personal data like name, address etc. which is stored in the database in plain text. Now I need a safe concept to encrypt the personal ...
Daywalker123's user avatar
0 votes
1 answer
109 views

Add the database layer to your application with a service or include it directly?

I am planning to set up a new Web-application that contains the following things: I want to use JavaEE with JSF for the Frontend & Backend combined with git-hooks to deploy them onto my server. ...
Rüdiger's user avatar
  • 103
0 votes
1 answer
148 views

Best way to handle environment specif fields in Hibernate

We have one microservice that will be deployed on two different environments(A and B). There are some common fields and also some are specific to the environment. Example: SomeEntity for environment ...
Mehraj Malik's user avatar
0 votes
1 answer
446 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
1 vote
2 answers
715 views

Optimal use of hibernate with mysql's stored procedures

I am working on a project (to use as a reference). The project uses mysql, hibernate and spring (REST) and is supposed to be a single microservice. I have come to find out that limiting user/consumer ...
zessi's user avatar
  • 9
-2 votes
1 answer
173 views

Is generating Hibernate Entities from database tables considered a bad practices?

On my current project it is a common practice to generate Hibernate Entities from database tables using NetBeans functionality. I'm normally used to first write the Entity-class and define the mapping ...
Pascal Petruch's user avatar
1 vote
0 answers
2k views

Using import.sql vs persisting JPA entities

In Hibernate ORM & Spring Boot, during the SessionFactory creation, SQL DML statements can be executed to create tables and/or insert data via files such as import.sql defined in the javax....
David Yee's user avatar
  • 111
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
  • 283
0 votes
4 answers
2k views

Best way to track user changes

I'm developing a webapp with users and roles, and I need to keep track of any changes that are made, so that I know when and who has changed a user role. I have my user table: CREATE TABLE user( ...
Manu's user avatar
  • 3
2 votes
1 answer
158 views

Reattachment of full entity graphs for frontend/backend applications which communicates using REST API/JSON?

I am trying to develop business application with separated backend (persistence, business logic, server side workflows) and frontend (presentation, some business logic) which communicates using REST ...
TomR's user avatar
  • 1,003
1 vote
1 answer
587 views

Does separating Domain model and Persistence model have impact on transactional aspect?

In this post, there is: For example, with your own persistence model, you are not able to benefit from the built-in change tracking functionality. And that means you will not be able to ...
Mik378's user avatar
  • 3,858
1 vote
1 answer
831 views

How to reuse boilerplate code for Hibernate session management?

My Java application uses Hibernate as an ORM framework. I find myself often writing code like this: Session session = HibernateUtil.getSessionFactory().openSession(); try { session....
Glorfindel's user avatar
  • 3,137
4 votes
3 answers
2k 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
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
1 vote
0 answers
451 views

Is BoneCP + JDBC a good alternative to JPA/Hibernate?

To some extent, I don't have a problem with JPA which inevitably needs an implementation such as Hibernate. However, it requires configuration and ORM. I don't specifically like using Hibernate ...
Mohamed Ennahdi El Idrissi's user avatar
1 vote
1 answer
286 views

Modeling complex tree structure

After asking it in stackoverflow : polymorphism-and-tree-structre I came to a conclusion that I am not being specific and my question is not about any specific technology so I will try to rewrite it. ...
Amit Mizrahi's user avatar
7 votes
4 answers
2k views

Examples of mid/large-scale web-apps built without an ORM?

I've been reading a lot of hate spewed on ORMs, and am genuinely interested in finding out if there is a better way of doing things. Unfortunately, while there are tons of books, blog posts, and ...
Saurabh Nanda's user avatar
2 votes
2 answers
10k views

How do I integrate hibernate and REST web service in java?

I am going to develop which will be web application as well as mobile (android / iOS / windows) application. The database in this application will be managed by Hibernate. Also as it is cross platform ...
Jignesh M. Khatri's user avatar
4 votes
2 answers
3k views

Micro-service database management?

Most people say when building micro-services, that it's best to have separate databases for each of the microservices. E.g: User-microservice: DB - User userId name Etc... Review-microservice: ...
James111's user avatar
  • 173
2 votes
1 answer
111 views

How to optimize a bloated entity that causes a huge query

I have an application that exposes a series of Web services. One of my entities has a bunch of one-to-many and many-to-many relations to other entities. My transactionality level is at DAO, and I'd ...
garci560's user avatar
  • 267
3 votes
1 answer
1k views

How to paginate local and remote data?

My team is currently facing a problem that we don't know how to tackle. Some technical details: we use Java 8, Hibernate, Spring, MySQL, and AngularJS for the front-end. We need to do pagination on ...
pgs's user avatar
  • 33
9 votes
5 answers
7k views

How to design a complex REST API considering DB performance?

I've been following some tutorials on how to design REST APIs, but I still have some big questions marks. All these tutorials show resources with relatively simple hierarchies, and I would like to ...
user3748908's user avatar
  • 1,607
7 votes
3 answers
26k views

Best way to deal with Hibernate 1->Many relationship over REST/JSON service

Problem: A Hibernate bi-directional One-to-Many relationship does not map easily to JSON. If default (Jackson) mapping is used there is an infinite recursion issue as the parent contains the children ...
BarrySW19's user avatar
  • 179
2 votes
1 answer
1k views

How, in Three Tier Architecture is Database Access Achieved

So I am attempting to make an application based on the architecture proposed by this image; (source: ibm.com) [1] However, I am getting very confused with how data access is achieved between the data ...
FinalFind's user avatar
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
1 vote
3 answers
930 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
7 votes
4 answers
8k views

Programmatically extending Hibernate table/entity definitions in Spring, how?

I would like to know if there is a way —maybe with AOP— to extend table/entity definitions so that I can add functionality across the board that requires persistence. Let me explain what I want to do ...
dukeofgaming's user avatar
  • 13.9k
3 votes
1 answer
84 views

Dealing with Users and User-Owned Data in an API

I have a question about the way I am architecting an API. Structure My API structure so far is like so (there is about 10 classes total, but many are similar, so I've reduced to these classes, and ...
Marco Pietro Cirillo's user avatar