Pitfalls: Should We Have a Constructor on JPA?

The data in any modern and distributed architecture, such as microservices, work as a vein in a system. It fits like a state in a stateless application. On the other hand, we have the most popular paradigms in the code, especially when we talk about enterprise OOP. How do you combine both archive and software … Read more

Querydsl vs. JPA Criteria – Introduction

I’ve used JPA Criteria for many years. The main advantage is its type-safe approach (compared to JPQL), but the code is quite complicated and not always straightforward. Recently, I came across a Querydsl framework and I saw its benefits immediately. The main benefits for me are: Type-safe approach. Fluent API with SQL style – the … Read more

Optimistic locking Test in spring data JPA

I’m trying to test the optimism locking mechanism in spring data jpa by loading a certain entity twice using findBy function, then updating the first one and asserting that when the second one is updated, it will throw an OptimisticLockingFailureException. But the problem is that no exception is thrown and the second update is done … Read more

Getting “java.lang.reflect.InaccessibleObjectException: Unable to make field private int (variable) (package) accessible” while trying to use JPA

I just learned about JPA and was trying to test it out. And I can’t get it to work at all… I get following error messages 7�� 02, 2022 10:09:51 ���� org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation INFO: HHH000204: Processing PersistenceUnitInfo [name: c57leePersistence] 7�� 02, 2022 10:09:51 ���� org.hibernate.Version logVersion INFO: HHH000412: Hibernate ORM core version 6.1.0.Final 7�� 02, … Read more

java – Spring Data JPA – Consider defining a bean named ‘entityManagerFactory’ in your configuration

I am developing an application in Spring, using Tomcat, Mysql5, Java8… The problem is that I cannot deploy it, due to “required bean ‘entityManagerFactory’ not found” problem. I have developed this project with my coworkers but they can perfectly deploy it with any problems, even if I copy-paste the same project in Spring Tool Suite. … Read more

java – HibernateOptimisticLockingFailureException when saving an entity in Spring MVC with JPA

The bounty expires in 4 days. Answers to this question are eligible for a +50 reputation bounty. FrancescoDS wants to draw more attention to this question. In my Java project (Spring MVC) I have the following entities: public class TariffeBaseComposizioni implements Serializable { private static final long serialVersionUID = 1L; @Id @Basic(optional = … Read more

java – Custom Sequence Generator in Spring Boot JPA

I want the empid to be generated in sequence like EMP_01,EMP_02….. Employee.classes import aurozen.assign.aurozenassign.StringPrefixedSequenceIdGenerator; import lombok.ToString; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; import javax.persistence.*; import java.util.ArrayList; import java.util.List; @ToString @Entity public class Employee { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = “emp_seq”) @GenericGenerator(name = “emp_seq”, strategy = “aurozen.assign.aurozenassign.StringPrefixedSequenceIdGenerator”, parameters = { @Parameter(name = StringPrefixedSequenceIdGenerator.INCREMENT_PARAM, value = “50”), @Parameter(name … Read more