Spring-Dao is different from Spring-mvc? - spring

I am still learning please advice if I am wrong.
I have one question regarding Spring Dao and spring MVC.
I know mvc - model, view, controller. We can say DAO as part of that MVC architecture.
But, why Spring-DAO is famous on it's own?
And why that Spring-DAO it self useful for bounding with other structures like hibernet and JSF?

MVC and DAO are two different patterns solving two different problems on two different application layers (ui layer and data access layer).
Why Spring-DAO is famous on it's own?
Consider a batch application which doesn't involve UI but lots of data access. Here spring's DAO support can greatly simplify in coding the data access layer by taking care of boilerplate code, simplifying transaction support etc.

The Spring Framework documentation explains the purpose of Spring DAO as follows:
The Data Access Object (DAO) support in Spring is aimed at making it easy to work with data access technologies like JDBC, Hibernate, JPA or JDO in a consistent way. This allows one to switch between the aforementioned persistence technologies fairly easily and it also allows one to code without worrying about catching exceptions that are specific to each technology.
This gives a overview of what Spring DAO is about, and deals with the part of your question about the relationship between Spring DAO and Hibernate.
On the other hand, Spring MVC and JSF are (mostly) about implementing web pages and web sites. They are orthogonal to Spring DAO, JDBC, Hibernate, JPA, JDO and so on. That is, they do different things.
We can say DAO as part of that MVC architecture
This is incorrect. Spring DAO can be used with Spring MVC, but it is not part of Spring MVC or the "MVC architecture".

Spring DAO vs spring Mvc is totally different technology for use different purpose. You can configure spring DAO inside of spring MVC but it is not part of spring MVC. Spring DAO is just a data persistence technology such as JPA, Hibernate. But Spring DAO more light and more efficient than JPA or hibernate because if you use JPA you need to use JPQL for database operation.if you are used hibernate you need to use HQL . Need extra effort to convert JPQL or HQL to SQL this process take some time so it is in efficient than Spring DAO. You can write pure SQL statement using Spring DAO and directly execute inside of database
Spring MVC is web base application design pattern. Model ,view controller as you mentioned. Spring MVC is not only MVC frame work java supported.Strust 2 also Based on MVC pattern. But the way of implement is deferent.

Related

This is in the company requirement list, I want to know the difference between them

what is the difference between spring core, spring boot, and spring MVC?
In Simple terms,
Spring MVC
Spring - It is a Inversion of control (IOC) and Dependency Injection (DI) framework. Spring helps you develop enterprise applications. Most information you can read here https://spring.io/projects/spring-framework
MVC - It is a design pattern (Model - View - Controller ) MVC , by definition, they are proven patterns and methods to design your application well. We have several design patterns such as Singleton, Factory pattern etc Read more about it here https://refactoring.guru/design-patterns
Spring-boot - It is a library built on top of Spring framework (like we have JARs) which helps develop production ready quick service oriented applications. You can still use typical Spring features. Read more about it here https://spring.io/projects/spring-boot
Spring-core - Just a named terminology representing core features of Spring framework such as IOC container, Dependency Injection, Bean scopes, Autowiring etc
Hope this helps!

Is Spring Data JPA a JPA implementation?

I am trying to "really" understand Spring Framework. I have got some fair understanding of Spring Core (DI), and Spring MVC.
For data part, I am now focussing on Spring Data JPA. As I understand, JPA is a standard specification, for which there are multiple implementations, Hibernate being the famous one.
Now, when I started Spring Data JPA, I was under the impression that Spring Data JPA is an independent implementation of JPA specification. It turned out that I am wrong.
If I understood correctly, Spring Data JPA is an abstraction layer provided by Spring, which internally uses other JPA provider (Example Hibernate), so typically it is like this:
Application ---> Spring Data JPA --> Hiberate --> JDBC ----> DB
Is my understanding correct? If so isn't Spring Data JPA misleading? It is NOT a JPA provider in itself, it is just an abstraction layer, which works on top of other JPA provider.
I am not sure if I really understand Spring framework or it is a complex framework altogether?
Can anyone please help me understand it?
I don't think it's misnamed (disclaimer: I am the project lead). All Spring Data projects list the store or API they're based on in their name. Spring Data JPA is basically Spring Data for JPA, just like Spring Data MongoDB is Spring Data for MongoDB, just like Spring Batch is Spring for batch applications, Spring Integration is Spring for integration projects.
Do correct your dependency graph for JPA:
Application -> Spring Data JPA -> JPA <- Hibernate -> JDBC -> DataSource
-> — uses
<- — implements
The same for MongoDB:
Application -> Spring Data MongoDB -> MongoDB Java driver -> MongoDB
etc. I'd still be interested where exactly you got the impression that Spring Data JPA is an implementation of JPA as neither the project page nor the reference documentation state that anywhere. In fact, especially the project page is very explicit about what functionality the project provides. Also, it might help to study the description of the umbrella project, which tries to set some fundamental context for all the modules contained in it.

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.

How to implement a Model in Spring MVC?

I'm new to Spring MVC, and I have been working on Codeigniter in php for a while,
In Codeigniter you implement Controller and Model by extending the particular class,
Ex : class Blogmodel extends CI_Model {
but in Spring MVC I didn't see such an implementation, except for controllers. Please can somebody give me a brief introduction on how would I perform the tasks that I did in a Model class in PHP, using Spring Framework.
Spring MVC is a presentation layer framework.
Is it not tied to any persistence mechanism, but can work seamlessly with persistence models.
In Spring (as well as other Java enterprise frameworks) the persistence layer is implemented using JPA (of which Hibernate is an implementation).
Spring MVC can easily operate on the JPA Entities.
You normally don't extend or implement anything, you just create the classes for the models you're interested in having.
If the model is supposed to be persisted somewhere, for instance in a database, you normally annotate the class with #Entity.

Why to use Spring not JSF (Advantages of spring over JSF)?

i don't know JSF very well, and i have a friend who is using only JSF
and he asked me a very open question, why do you use spring not jsf ?
and because of there are a lot of things about spring in my mind
i wasn't able to give some straight answers
so what are the advantages of spring over JSF ?
Spring and JSF are quite a different frameworks.
JSF is more of a web application framework and you can still use spring with JSF to manage the relationship and creations of the objects.
Spring is more of an entire j2ee application framework/plaform.
Spring MVC and web flow will help you to design web applications similar to JSF.
But spring with its IOC concept also brings a lot of other modules such as dependency injection, aop, DAO, ORM, integration, batch and social tools and much more.
You can also check the JSF-Spring combination - http://www.springsource.org/node/422
JSF is presentation layer, Spring business layer (roughly said), they can be used together and do not compete.
As said before, JSF is a request-driven, MVC web-framework, built around a light-weight IoC container and is designed to simplify and standardize the way UI-layer of a web-application is built.
Spring, on the other hand, is less concerned with UI-layer but its precise definition is hard to formulate. It can be said that the primary function of SF is to tie together different layers of a web application in a standardized way, at the same time abstracting away the implementation details of a particular web technology from the developer. As one of the consequences, the developer is freed from implementing "plumbing" and instead gets working module interconnections which are tested, implemented and used relatively easily. This should provide a boost to productivity and shortens development cycle.
This abstraction can be viewed through various Spring modules - Spring is heavily modularized, so you choose which components of the framework will you be using. Though it features a MVC framework (SpringMVC is mostly written as a reaction to the Jakarta Struts, whom the Spring developers deemed poorly written), Spring lacks a dedicated presentation module so you're free to use most of existing UI technologies (e.g. JSF, GWT-oids, etc.) - once you properly configure them in Spring.
In another words, the "scopes" of JSF and Spring are quite different (though not totally disjunct).

Resources