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
Related
After migration of Spring Boot to version 3.1 and springdoc-openapi libraries to 1.4.1:
springdoc-openapi-ui
springdoc-openapi-security
springdoc-openapi-data-rest
I faced issue ClassNotFoundException: org.springframework.data.rest.webmvc.support.DefaultedPageable
Also now on Swagger UI page controllers and schemas for #Entity are generated, however earlier there were only endpoints from #RestController, request and response DTOs. Are there any way to disable it?
From your description, you don't need to load springdoc-openapi-data-rest. (You will load unecessary beans related to spring-data-rest)
If you just need to enable the support of Pageable, you can just add the following line:
SpringDocUtils.getConfig().replaceWithClass(org.springframework.data.domain.Pageable.class, Pageable.class);
This is explained here: https://springdoc.org/
Section [Spring Data Rest support]
Or, if you want to depend on spring-boot-starter-data-rest, then add the dependency.
I have a maven project with many separate modules. I would like to move my Spring Boot JPA Entities (annotated with #javax.persistence.Entity) in a common module, and use that module as a dependency in Spring Boot.
The trouble is that when I do that, Spring Boot can no longer find data for those entities. It returns empty lists. My current workaround is to annotate the models with #MappedSuperclass in common and have dummy classes in Spring Boot which have the #Entity annotations and extend the classes in common. This is quite stupid though, there has to be a better way to do this.
Thanks.
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'
i created a maven project, and added all dependencies i need.
i have some repositories using the spring-data-jpa, and i added some integration tests.
now i need to add ontop of it spring-data-rest, if i understand it is based on springmvc.
but all examples i found, i need to add spring boot to start the app.
i noticed also all new spring projects use spring boot.
this means that i have to learn and use it for my projects?
how can i use spring-data-jpa+spring-data-jpa with an existing servlet3 project
The reason all examples are written using Boot is that Boot is indeed the way you should start a new Spring project these days. It free's from a lot of the tedious work of setting up the infrastructure, finding dependencies in the right version etc.
To use Spring Data REST without Boot, simply add the necessary dependencies to your project. The easiest way to do this is to use the Spring Data Release Train BOM (which will help you pulling in the correct matching versions) along side the version-less dependency declarations for Spring Data REST WebMVC and - in your case - Spring Data JPA.
Then go ahead and either register RepositoryRestMvcConvfiguration as Spring bean (either through XML configuration or JavaConfig).
All of this is also documented in the reference documentation.
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.