Skip to main content
9 votes
Accepted

Micro-service database management?

Microservices do come with a performance penalty for some cases, which is offset by better scalability. It may seem like a paradox, but sometimes you need to make an individual operation slower in ...
Michał Kosmulski's user avatar
8 votes

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

Stack Overflow uses a micro-orm. Unlike Hibernate, it's just a thin veneer around SQL queries. Answers to your questions: By writing a SQL query. It can vary from one line of code to about 40. ...
Robert Harvey's user avatar
6 votes

Micro-service database management?

The reason why you often have a database for each micro-service, is in order to separate each part of the system. If you store everything in one database, you will (as mentioned by Michal Kosmulski) ...
Niklas H's user avatar
  • 645
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
4 votes

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

You should check out Elixir's Ecto, which is a domain specific language (DSL) for interacting with (mostly relational) databases and writing queries. It goes well with the Phoenix framework, which ...
Gagandeep Bhatia's user avatar
4 votes

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

There are various design patterns that are useful for applications that are not using ORM. I'd suggest reading through Martin Fowler's book, Patterns of Enterprise Application Architecture, which ...
Jules's user avatar
  • 17.8k
3 votes

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

Aggregations and compositions are specialized associations that carry some additional semantic (i.e. meaning): UML doesn't specify the semantic of aggregation ("Precise semantics of shared ...
Christophe's user avatar
  • 78.7k
3 votes
Accepted

Decouple business logic from DTO

I'd consider a top-down approach. What kind of code would you like to see in the top level method of the service? I'd prefer seeing a short list of steps needed to fulfill the service request. It ...
COME FROM's user avatar
  • 2,686
3 votes
Accepted

Can I reduce locking for this scenario using Hibernate and H2

I assume that H2 will get a SHARE lock when querying the database, and needs a WRITE lock to add new rows the table, which it cannot do whilst there is a SHARE lock on a table. That is only true if ...
David's user avatar
  • 306
3 votes

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

Both your approaches raise some concerns. The main concern about the first approach is that you'll end up with a lot of duplicate methods. This isn't exactly a problem though, because both methods ...
user352033's user avatar
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.8k
3 votes

Optimizing writes over the same entity in relational DB

Although the frequency of updates per minute may not seem excessive, and your database should have no difficulty handling it, it may be worth considering implementing an in-memory buffer to keep track ...
George's user avatar
  • 168
2 votes
Accepted

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

The linked blog post is rather vague and seems be a confusion of active record and entity object pattens rather than using data transfer objects. Bear in mind that underneath whatever orm or wrappers ...
Ewan's user avatar
  • 77.6k
2 votes
Accepted

How to reuse boilerplate code for Hibernate session management?

Make use of inheritance. This code already follows the Template Method pattern, with doWork() being the method called by the template. Turn this code into an abstract superclass and subclass all of ...
kdgregory's user avatar
  • 5,250
2 votes
Accepted

Best way to track user changes

I'd go with the second one if you're doing it that way; the ideas "user" and "user role change history" are two different things. It'll make it easier to differentiate between the actions "check what ...
h0n3ycl0ud'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

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
Accepted

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

So essentially you've run into performance issues, and decided to go lower down in abstraction levels. This is a sensible approach although sometimes it's not the most long term approach; but it ...
Diane M's user avatar
  • 2,076
2 votes

Optimizing writes over the same entity in relational DB

Roll a new GUID for each voting event, and append a one-line entry to a text file of votes, perhaps in CSV format. Either fsync() the write immediately, or have a background thread issue fsync's every ...
J_H's user avatar
  • 7,600
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

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

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

Mapping bidirectional 'toMany' relation from DTO to entity

What's the best approach to map DTO to entity and vice versa for a complex objects? The best approach is to not have complex objects. Many small objects are preferable to large god objects that try ...
candied_orange'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,456
1 vote

concept for de- and encrypting personal data in web portal

Having a database store encrypted contents and end-to-end encryption are quite frequently NOT feasible approaches. The problem is who has access to the plaintext contents. E.g. for a web app: The ...
amon's user avatar
  • 135k
1 vote

Best way to handle environment specif fields in Hibernate

Having branches in your code that are enabled per customer is not a practical solution. 20 customers with special demands later and your codebase is a pile of excrement. So I'll recommend you use ...
marstato's user avatar
  • 4,628
1 vote

Optimal use of hibernate with mysql's stored procedures

You don't need stored procedures to prevent SQL injection. Sure it provides one more barrier between the database and the outside world, but if you use HQL parameterized queries, the criteria API etc. ...
Kayaman's user avatar
  • 1,960
1 vote

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

You said "Frontend does processing of those JS entities and sends them back to the backend." I suppose that You are returning full graph. Why don't You return json patch (https://www.rfc-...
Mirza's user avatar
  • 111

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