Skip to main content
6 votes
Accepted

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

In the long run, going database model first will very often pay off compared to what appears to be a quick win of going client model first. Before I explain, let me just disclaim that your domain ...
Lukas Eder's user avatar
  • 1,110
3 votes
Accepted

Implementing transactional entity lockouts with Spring and JPA

Short Answer Don't use JPA locking to implement this. It's insufficient to deliver a good experience in the style you defined. Record check-out information about the widgets instead. Why? Some aspects ...
joshp's user avatar
  • 3,491
3 votes
Accepted

How to represent and validate website URLs for a JPA entity

From@URL Java Doc: Validates the annotated string is an URL. The parameters protocol, host and port are matched against the corresponding parts of the URL. and an additional regular expression can be ...
Laiv's user avatar
  • 14.7k
3 votes
Accepted

Reserving database independence using Spring JPA

If we start developing using a self-hosted PostgreSQL server and later want to change to Amazon RDS PostgreSQL or SQL Server, will we run into lots of problems? Not really. We recently migrated ...
Laiv's user avatar
  • 14.7k
2 votes

Problem related to optimistic locking performance

You are correct - that will occur. But i think that you dont need optimistic locking for the posts. AFAICT, social networks allow the user generated content to be altered only be the owner/poster ...
marstato's user avatar
  • 4,628
2 votes

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

There's a limt on how long column names can be in mosd DBMSes: Postgres and MySQL allow 64 characters, Oracle only 30. It's fine when you have a long name for something primary, but once you start ...
9000's user avatar
  • 24.3k
2 votes
Accepted

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

You need to find a balance. AnIncrediblyLongVariableOrTableName is almost as hard to deal with as TooShrt - especially when you're looking at a block of code (or a sproc) that mentions a half dozen ...
Dan Pichelman's user avatar
2 votes

Query with a lot of fields and joins

Even when creating a fresh application and deciding to use an ORM, it can be very tricky, especially if you're not familiar with how the ORM works. An ORM can make it seem easier to deal with the ...
Kayaman's user avatar
  • 1,960
2 votes
Accepted

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

Disclaimer: These assumptions are based on a quick glance at the codebase It looks as if the interfaces are used as a "disguise" for entities to be directly used as domain objects / dtos. This does ...
Kayaman's user avatar
  • 1,960
2 votes

Pattern for syncing databases with undo option

Sounds like a nightmare. In theory, if you publish the events to a message queue you can have them processed against the master database and have undo event work fine. However, with multiple clients ...
Ewan's user avatar
  • 77k
2 votes

Best practices for retrieving data scattered over multiple tables

Data Transfer Objects are used (among other things) so you don't send your entities over the network, and therefore create a dependency between the entity and the output of your API, this is why you ...
Kayaman's user avatar
  • 1,960
2 votes

performance suggestions on Aggregate root containing thousands of child entities

Leaky Abstractions and Abstraction Bypasses When the abstraction breaks, and bypassing it feels prefferable, its time to fix the abstraction. Find a cheap way to speed it up, and put off actually ...
Kain0_0's user avatar
  • 16.2k
1 vote
Accepted

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

It looks like you are writing documentation which shows a user what the "notation" will be. As a user I will read the documentation, copy and paste whatever you have written into my code and ...
Ewan's user avatar
  • 77k
1 vote

Best practices for retrieving data scattered over multiple tables

There are two questions in your question. Question 1: How to fetch scattered data accross tables? Question 2: "some guys in my team told me that the DTOs are the Controller responsibility and ...
Alexander Petrov's user avatar
1 vote

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

The first scenario seems a good approach. By default, the method getCar should just return the Car object without the Engine (as it is set to be fetched lazily). If the controller needs the Car and ...
Marc's user avatar
  • 121
1 vote

Pattern for syncing databases with undo option

OK I'm going to add a second answer in the assumption that the replication of the data isn't really the problem at all. Its applying an undo operation. First off, you have to take into account that ...
Ewan's user avatar
  • 77k
1 vote

Normalize timestamp values or have multiple SQL queries

Gah! Spare me from all these nulls! The problem with null is it doesn’t tell you exactly what it means. Leave this field blank when displayed? Don’t set any upper limit? Report that no matching date ...
candied_orange's user avatar
1 vote

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

As you have already noted, your "reverse engineered" requirements are contradictory: numeric part of user handle is 4 digits more than 10000 users name part can be freely changed This ...
Hans-Martin Mosner's user avatar
1 vote

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

I know I should refactor in such a way that I don't need to create each class on each project I make Not really. Event (as an entity) and Event (as a bean) looks the same but they are indeed ...
Laiv's user avatar
  • 14.7k
1 vote

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

If you are going introduce library which would be used in different projects then you have to segregate changes in DB and your library. On approach is to create and maintain two classes/data models: ...
ADS's user avatar
  • 164
1 vote

Best practice for references in DTOs and entities in Spring

These all eventually make it into a database having IDs anyway, so my vote is for IDs. Object references can have the peculiar property of pointing to two different objects that are functionally ...
Robert Harvey's user avatar
1 vote

Jpa Repository save inside a for loop

If the count of the inserts/updates is the only thing you need, quick (and possibly dirty) solution might be to keep using saveAll method and selecting the count of the entities in the database before ...
Filip Halaxa's user avatar
1 vote

Query with a lot of fields and joins

The ORMs are a helpful tool to abstract a lot o things related to the update, insert, select and delete informations from a database. I think they are popular because most of the applications does ...
Dherik's user avatar
  • 2,446
1 vote

performance suggestions on Aggregate root containing thousands of child entities

But my question is performance. Just to add a comment to a sub-task we are loading en entire aggregate root into memory. How can this be efficient? It isn't. Don't do that. This is not a question ...
JimmyJames's user avatar
  • 27.6k
1 vote

Returning JPA Entities in Rest Api's?

For quite simple apps, returning such entities works just fine and gets you started really quick. You are likely to need those for the database interactions anyway and the returned entities are ...
Andy's user avatar
  • 10.3k
1 vote

Using Map to pass query parameters in DAO

To ease the tedium of creating the map I'll often write a little utility:. (skeleton code) Map addKeyValuePairs(Map m, Object...pairs) { // TODO test that pairs has an even number for (int i=0; ...
user949300's user avatar
  • 8,859
1 vote
Accepted

Using Map to pass query parameters in DAO

It's over engineering or just paranoia ;p ? I don't think it's either. Yes, a map is a generic data structure but it's also the first thing you reach out for when you need key-value or param-value ...
Bogdan's user avatar
  • 3,620
1 vote
Accepted

Correct way to separate JPA with Service layer

I did solve this issue so this approach is not neccesary. Here is how I did it: Using transformers. So the field area is defined like this: @Transformation(fetch = FetchType.EAGER, optional = false)...
Mariano L's user avatar
  • 111
1 vote

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

I think your confusion stems from the Product table's general lack of utility, since it contains an ID and nothing else. However it's not a big deal. When defining JPA entities, I would start with ...
Andrew's user avatar
  • 251
1 vote

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

Sometime ago, i asked on SO a question that include if i have to implements my service as they're using JPA managed entities ? Here are the two points of my own answer that should interest you : ...
Walfrat's user avatar
  • 3,496

Only top scored, non community-wiki answers of a minimum length are eligible