Spring-data-rest 2.5.6 -> Setter no longer called - spring-boot

When I upgrade from Spring Boot 1.4.1 to 1.4.3 Spring-data-rest is upgraded from 2.5.3 to 2.5.6.
After that a #OneToMany property in a SDR-managed Resource is no longer set via its setter (I assume now via direct field access).
What has to be done that the setter is called again? I already tried #JsonProperty/#JsonIgnore - with no luck.

Try to use a property access in entities.
Look example #2 in my repo: https://github.com/Cepr0/restdemo

Related

ElasticsearchAutoConfiguration not available in spring boot autoconfigure 2.7.6

I am working on spring-boot upgrade from 2.2.2.Release to 2.7.6. I am noticing org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration is not available in spring-boot-autoconfigure:2.7.6. Is there any substitute for ElasticsearchAutoConfiguration class which is introduced in 2.7.6 version.
I checked the spring boot project source code but didn't find the ElasticsearchAutoConfiguration class present in latest version
It looks like the org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration class was removed in favor of ElasticsearchDataAutoConfiguration in the same package in b780e52 since Spring Boot 2.3.0.
See also https://github.com/spring-projects/spring-boot/issues/19668.

Spring data commons 2.7.3 doesn't update when using save()

I have recently upgraded my project to java 17 and spring boot 2.7.4 and spring cloud 2021.0.4. I am using mavenBom for spring cloud dependency management. It has brought in spring-data-commons-2.7.3.
With the upgrade, the CRUD repository's save() doesn't seem to be updating the existing objects. I am getting a duplicate key exception. (org.springframework.dao.DuplicateKeyException: Document with the given id already exists).
I have already tried enabling transaction management, but to no avail.
Could you please help.
auto-upsert is not supported by spring-data-couchbase v 4.4.3.
If you want to use upsert() on an entiy class that has an #Version property, you'll need to explicitly use template.upsertById() or introduce your own repository.upsert() method. Or override the repository.save() method.

How to edit Hibernate settings in a Spring-Boot project?

Essentially what I'm trying to do is to add this property change to hibernate so I can enable instantiation of composite/embeddable objects when all of its attribute values are null:
hibernate.create_empty_composites.enabled
I am aware that the usual way to edit Hibernate is in the application.properties file like so:
################################################################################
# JPA MANAGEMENT #
################################################################################
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true...
...
spring.jpa.properties.hibernate.create_empty_composites.enabled=true
But the spring.jpa.properties.hibernate.create_empty_composites.enabled=true isn't working. I'm not sure if Spring just doesn't recognize certain properties or if it's just the wrong place to put it.
What I'd like to know is if there is another way to edit the Hibernate properties directly or if there is another fix.
Analysis
The base assumption. More likely you are using Spring Boot 1.5.*.
Spring Boot 1.5.* uses Hibernate 5.0.*. GitHub proof.
Hibernate supports the hibernate.create_empty_composites.enabled setting since the 5.1 version.
GitHub proof.
JIRA proof (?): [HHH-7610] Option for injecting empty (non-null) embedded when all columns are NULL - Hibernate JIRA.
Release notes proof: ORM 5.1 feature release.
Solution
Please consider upgrading the Hibernate dependency in your pom.xml to a more recent version (5.1 and higher).
After that, it should work just fine:
In addition all properties in spring.jpa.properties.* are passed through as normal JPA properties (with the prefix stripped) when the local EntityManagerFactory is created.
— Spring Boot 1.5.* reference, 77. Data Access, 77.5 Configure JPA properties.

Cannot access web context objects with thymeleaf in Spring boot project

From looking at the thymeleaf documentation, I've tried to access web context objects with thymeleaf in my Spring boot project in this manner:
<p th:text="${#request.getRequestURL()}">lol</p>
which results in the following exception:
org.springframework.expression.spel.SpelEvaluationException: EL1011E: Method call:
Attempted to call method getRequestURL() on null context object
From this error it seems that I might be missing a dependency? I've seen a similar question, where the solution was to add an extras thymeleaf package as a dependency.
However, it is stated in the thymeleaf documentation that these objects and variable maps are always available to be invoked so I guess that shouldn't be the case here.
I'm using the release 1.5.1 of spring-boot-starter-thymeleaf as well as a number of other spring-boot-starter packages like web and security.
I got it to work with thymeleaf-spring4:3.0.0.RELEASE and thymeleaf-layout-dialect 2.0.0, so seems like these are the minimum versions required.
The spring-boot-starter-thymeleaf:1.5.1.RELEASE only provides thymeleaf-spring4:2.1.5.RELEASE and thymeleaf-layout-dialect 1.4.0.

JpaRepository and CrudRepository error

Why happen such error?
I am using Spring Data JPA 1.3.3 , Spring 4.2.8 and Spring MVC 4.2.8.
UPDATE:
Error as code block
Error:Error:line (8)java: name clash: save(java.lang.Iterable) in org.springframework.data.jpa.repository.JpaRepository and save(java.lang.Iterable) in org.springframework.data.repository.CrudRepository have the same erasure, yet neither overrides the other
All my libraries added as IntelliJ Idea's Module. Only JSTL is downloaded by Maven.
It seems you have dependency problem. An older version of Spring Data Common with Spring Data JPA might be the problem.
For spring data jpa, It's not really good idea to write native query in repo. Unless your demands are just to hard to write query methods.
For your case, you just need simple query methods like this
List<User> findByFirstName(String firstName);
Return list of User because many Users might have the same userName
Take a look at spring data doc Query methods
Hope it help :)
For those who face the Ignite Spring Data and Spring JPA dependency issue - you need to downgrade org.springframework.data:spring-data-jpa version to 1.11.23.RELEASE. Thanks to #chirdeep-tomar comment!
In my project compatibility issues of IgniteRepository and CrudRepository with deleteAll() method were solved with the following Maven configuration:
'org.springframework:spring-core:5.2.3.RELEASE'
'org.springframework.data:spring-data-jpa:1.11.23.RELEASE'
'org.apache.ignite:ignite-spring-data:2.9.0'
'org.apache.ignite:ignite-core:2.9.0'
'org.apache.ignite:ignite-spring:2.9.0'

Resources