Spring Boot External Hibernate JPA Entities - spring

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.

Related

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

What Spring annotations can we use in Hybris commerce project?

I was reading about Spring core module and came across Spring annotations that I did not see till now in the Hybris project:
#Component,#Qualifier
Are these used in Hybris projects?
Hybris uses both. Annotation Injection and XML Injection. You can also use both. I recommend you, to define a clear strategy when you use which one.
For example:
Controller - Annotation Injection
Facade - XML Injection
Service - XML Injection
To your point, which kind of Annotation you should use, have a look here:
What's the difference between #Component, #Repository & #Service annotations in Spring?
In common said, there is not really a different. It's just nice to use the correct Annotation for the correct class.
Hybris 6.6 uses Spring 4.3. The usual annotations like #Autowired, #Required, #Controller, and many others should work.
If you have access to Hybris Help, have a look at "Spring Framework in SAP Commerce": https://help.hybris.com/6.6.0/hcd/8c63621986691014a7e0a18695d7d410.html
There is:
Dependency Injection
Interface-Driven Design
Beans (and aliasing)
Spring Profiles
Spring MVC
Spring Integration
etc

Is there a way to add JPA annotations at runtime to JAXB generated bean classes using Spring Data JPA?

As part of project requirements, where we need to handle certain volume of data through REST call. Customer would call in a REST service, passing in a payload and distributed a jar of JAXB generated bean classes. Now these classes are not Entity beans by itself. Service should be able to use these JAXB objects and persists them as Entities using Spring Data JPA. But this required #Entity and other annotations required for JPA.
Is there a way to let Spring Data JPA know that these are entities and perform CRUD operations using JpaRespository etc? I know couple of options are discussed Separating JPA information from POJO and Is it possible to build a JPA entity by extending a POJO? . But those two are Hibernate specific solution and have control on the source code of the JAXB beans.
But I'm looking at solution more abstract in Spring Data JPA out of box.
Thanks

Spring Boot Spring Data JPA - Don't scan for Implemented classes

I've noticed in our spring boot projects that during start up, spring seems to scan the classpaths for an implemented version of each of our DAOs.
We don't currently have implementations of our DAOs. We just extend the JPARepository and let spring data create the daos for us.
Is there any way to tell spring boot not to search for the implementations? We think it may help shave some time off of our start up times.

Spring boot JPA without Spring data

I'm gradually introducing Spring Boot to a Spring JPA project. My intent was to first introduce Spring Boot, than at some later stage Spring Data, but I was not able to find any examples (nor a suitable starter) that uses Spring Boot + JPA without Spring Data.
How come? Is there any benefit of introducing Spring Boot to Spring JPA project, without Spring Data, or does it make sense only with Spring Data in place.
Any article link or example code would be helpfull and appreciated, thanks
More context
I'm working with a live project so every change introduces risk. We're discussing of moving from XML to JAVA based configuration, and I'm advocating adopting Spring Boot at a same time, but I lack persuasive selling points.
Personally, I want to include Spring Boot on all layers to boost future productivity, but I need to argue better the direct immediate benefits of using it in our Service/DAO module which is at the moment based on Spring/JPA/Hibernate with the good old manual CRUD implementations.
So I need selling points for using Spring Boot on a persistence layer, but ones that span beyond Spring Data (e.g. configuration gains, maintenance, testing...anything)
As folks have said above, there is no Spring Boot JPA. It's either Spring Boot Data JPA, or JPA on its own.
The immediate benefits that I could think of:
With Spring Data JPA you don't write the Dao layer. For all CRUD operations, the CrudRepository interface gives you all you need. When that is not enough, all you have to use is the #Query annotation to fine-tune your SQLs
Configuration by convention. For example, with Spring Boot, just having the H2 dependency in the classpath gets Spring to use the H2 in-memory database, gives you Datasource configuration and transaction management (only at the JPA repository level) by default
Ability to create micro-services. With Spring Boot, you can create micro services that can be deployed and run on a number of boxes with java -jar ...
You can enable annotation-based transaction with one simple annotation: #EnableTransactionManagement
Java configuration over XML. This advantage is not to be underestimated
A lot less code (the DAO layer) means also a lot less maintenance
The native ability to provide a RESTful API around data: https://spring.io/guides/gs/accessing-data-rest/
It all depends where your company is heading for. If they want to deliver business value faster and move towards more a DevOps operating model, then the above advantages should be enough selling points for any organisation
Spring wiht JPA (for example Hibernate) but without Spring-Data-Jpa means that you direct interact with the JPA Entity manager and. Typical you use it to implement your own DAO from it and use the #Respository annotation.
#Respository
public class UserDao {
#PersistenceContext EntityManager em;
public User findUserByLogin(Sting login) {
....
}
}
Even if there is no starter project, you could use a Spring-Data-JPA project, and implement the Repository in this old fashion style. (And then you could show how simple it become when you just write Spring-Data-JPA interfaces)
As far as I known, spring-boot means more convenient not any independent business feature.
In other words, spring-boot helps you to start, configure your application in some automatically way. But you can do that without spring-boot with your own specific configuration.
So, you are going to use spring-boot in your application means you are going to use spring-boot's auto configuration feature with your original application.
Actually, Spring JPA implemented in spring-data-jpa is what you are looking for not spring-boot. Of course, spring-boot can simplify your work dramatically.

Resources