I’m trying to use hibernate to create objects, which are not domain models, but I get a incomprehensible error message. My Java code: The class: Stacktrace: The schema for the table: Versions: Frankly, i’m clueless about why it cannot instantiate this class. Answer You get a NullPointerException i…
Tag: jpa
Spring Boot + JPA : Column name annotation ignored
I have a Spring Boot application with dependency spring-boot-starter-data-jpa. My entity class has a column annotation with a column name. For example: SQL generated by this created test_name as the columns name. After looking for a solution I have found that spring.jpa.hibernate.naming_strategy=org.hibernate…
Hibernate – automatically delete children when updating parent
I have two tables. Site have a lot of Sectors. When I try to edit the list of sectors of a site, for example I have 3 sectors initially, so I delete one sector and I update the site. in the database are three sectors of the Site. Is it possible that the sectors are automatically deleted when I update
JPA PessimisticLockScope.NORMAL and locking “relationships”
I am studying JPA Documentation and encountered the following lines: Entity relationships for which the locked entity contains the foreign key will also be locked, but not the state of the referenced entities (unless those entities are explicitly locked). Element collections and relationships for which the en…
JPA @Version field doesn’t get incremented
I’m new to JPA and Hibernate and I have a problem with optimistic locking. I have a class which has an @Version annotated field. When I update the Entity represented by this class, the version counter does not increase. Here is my code: The class: and here is the main method: and here is what the consol…
First level cache not working with JPA and Hibernate
I an new to use hibernate caching (first level, 2nd level and query cache). My project is configured using Spring MVC and JPA. I am testing first level cache using JUnit test case below. And my entity class is defined as : This should execute native query once in case first level cache is by default enabled. …
Why is there a class with entity name plus an underscore for JPA entity class
I am new to JPA, I have created a class like the following I noted that there is another class with name as my entity java class Programme.java with an underscore i.e. Programme_.java. What is this class and why is this generated. Is there any way that I can stop its generation? the code for the Programme_.ja…
Query creation in Spring Data – dynamic where clause
Is there a way in Spring data to dynamically form the where clause? What I want to do is have a method (which is like the findBy / get method) which runs a WHERE and AND using the mentioned properties which are NOT NULL. For example, Our method looks something like this Thanks. Answer Take a look at JPA Speci…
Transaction marked as rollback only: How do I find the cause
I am having issues with committing a transaction within my @Transactional method: When I call methodB() from methodA(), the method passes successfuly and I can see “OK” in my logs. But then I get The context of methodB is completely missing in the exception – which is okay I suppose? Somethi…
What is the difference between CascadeType.REMOVE and orphanRemoval in JPA?
What’s the difference between and This example is from Java EE Tutorial, but I still don’t understand details. Answer From here:- Cascading Remove Marking a reference field with CascadeType.REMOVE (or CascadeType.ALL, which includes REMOVE) indicates that remove operations should be cascaded autom…