JpaRepository and CrudRepository error - spring

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'

Related

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.

Do spring-data-jpa annotations not work in webflux environment?

I am new to spring webflux and want to build my first application.
I am used to build my entities first and give them anntotations like javax.persitence.Entity, javax.persitence.OneToMany, ... and let spring generate my tables for me.
But...in all tutorials I found there is always only the #Table annotation used and there is no spring-boot-starter-jpa dependencies in the pom. Webflux does not even seem to work anymore if I add that dependency (Then there were no ReacticeCrudRepositories found anymore). All tables were created manually.
So using spring-boot-starter-jpa and its annotations seems to be forbidden.
But how do I model my entities, e.g. OneToMany and ManyToOne when I do not have my annotations anymore?
Is there no auto-generate option anymore?
Thank you very much

spring persistence xml

What is the difference between:
persistenc.xml can be configured with hibernate properties OR Javax.persistence properties.
What scenarios would you use either one.
I tried using javax.persistence but my spring app would not work.. changed it to hibernate and it started working.
javax.persistence is the standard. Hibernate is an implementation. If you are completely sure that your DB layer will always be handled by Hibernate, go ahead and configure using Hibernate. If not, use javax.persistence, so that you could change your DB layer in the future.

Spring Hibernate Connection through AOP standalone application

I am trying to develop Annotation based Spring Hibernate standalone application to connect to DB. I've gone through the some blogs and wondered like we should not make use of hibernateTemplate becoz coupling your application tightly to the spring framework. For this reason, Spring recommends that HibernateTemplate no longer be used.Further more my requirement is changed to Spring Hibernate with AOP using Declarative Transaction management.I am new to AOP concepts. Can any one please give an example on Spring Hibernate Connection through AOP. That would be a great help to me.
Thanks in advance.
If you are looking for exemples of project structures, you may want to use maven archetypes which provide you an already working Spring + Hibernate or Spring + JPA configuration.
They may provide you also a web layer (or not) but you can remove it if you want.
To try that, install maven and type:
mvn archetype:generate
By the way, I don't think using HibernateTemplate is a big deal. Many people still use it. But you'd better inject the Hibernate session factory and use contextual sessions with getCurrentSession()
I'd use JPA instead of plain Hibernate. You can of course use Hibernate as a provider. I guess that you know how to run Spring container in standalone application. Just follow the steps from documentation here. Use LocalContainerEntityManagerFactoryBean. Then read about transaction management.
There is a new feature that lets you start JPA without persistence.xml file. Read here.
If you still want to use plain Hibernate follow the docs.

Spring Framework Saving Data to Multiple Tables

Newbie here...
I'm working on a Spring MVC app and their JDBC api for data access. How would I go about saving data to multiple tables? The insertion needs to be such that if there's an error or something goes wrong, nothing gets inserted and rolled-back. Would this be Spring's transaction support? If so, the official documentation for transaction support is very confusing to me. Does anyone have a good source for learning how to do that?
I'm using Spring 3.1, Oracle 11g, and Tomcat 6.0
Yes, spring supports transaction. You can use DataSourceTransactionManager to configure your bean.IF you find xml mapping confusing you can use annotation #Transactional. Spring's annotation support for transactions are really simple. Spring in Action book has examples for transaction management.

Resources