Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring data alternatives

Currently We have an enterprise application that works with spring and JPA. Today we are planning our next generation server.

We are debating whether to use spring-data in our project? It seems to increase productivity and development times.

Are there any alternatives to spring-data to consider? Why not using spring and JPA alone? What do you suggest?

Bear in mind we are starting to develop from scratch so no constraints are available other than:

  1. we use mysql and mongoDB
  2. we code in java
  3. we will develop client side code in GWT.

Currently we have a layered architecture. We have a Service layer and a manager layer, which takes care for persisting and business logic. Whoever built that didn't see a good reason to insert the third DAO layer.

like image 538
Urbanleg Avatar asked Oct 10 '13 14:10

Urbanleg


People also ask

What is better than JPA?

Also, JPA is thought to be better suited for more sophisticated applications by many developers. But, JDBC is considered the preferable alternative if an application will use a simple database and we don't plan to migrate it to a different database vendor.

What is alternate to JPA?

JPA alternatives If JPA and Hibernate are not a good fit for your use case, you can use any of the following frameworks: MyBatis, which is a very lightweight SQL query mapper framework. QueryDSL, which allows you to build SQL, JPA, Lucene, and MongoDB queries dynamically.

Which is better CrudRepository or JpaRepository?

Crud Repository doesn't provide methods for implementing pagination and sorting. JpaRepository ties your repositories to the JPA persistence technology so it should be avoided. We should use CrudRepository or PagingAndSortingRepository depending on whether you need sorting and paging or not.

Which is better Spring Data JPA or Hibernate?

Conclusion. Hibernate is a JPA provider and ORM that maps Java objects to relational database tables. Spring Data JPA is an abstraction that makes working with the JPA provider less verbose. Using Spring Data JPA you can eliminate a lot of the boilerplate code involved in managing a JPA provider like Hibernate.


Video Answer


1 Answers

There are some technical benefits of Spring Data over Spring + JPA, which in a pure SQL environment, I think give Spring Data an advantage:

  • Spring Data uses the same CrudRepository interface for all implementations, so you'll have less effort to switch between JPA to MongoDB
  • Spring Data saves you writing the same methods again and again. You just add the method to the interface and it'll generate it for you (e.g. UserRepository.findByUsername())
  • You can save boilerplate on REST implementations for JPA, MongoDB and others (see http://projects.spring.io/spring-data-rest/)
  • If you wanted to experiment with other persistence or indexing services, then there are Spring Data implementations for both mature and newer technologies such as for Neo4j, Hadoop, Solr, ElasticSearch, fuzzydb.

Given that you use MySQL and MongoDB, I think Spring Data is a strong candidate, as it allows developers to code to a single data access API (Spring Data) instead of two (JPA and the MongoDB Java Client).

Regarding the existing architecture, it sounds as though your manager layer is implementing either a Rich Domain pattern, or Active Record.

Spring Data is in my view very well suited to Rich Domain when combined with injection of services using Spring's @Configurable.

Lastly, I'd say that Spring Data also gives a significant advantage when needing to implement services for things like Spring Security and Spring Social, which use MongoDB or others instead of SQL.

We did this in the fuzzydb sample webapp that can be found here. (Disclaimer: I'm the currently sole recent committer on fuzzydb, and haven't touched it for a number of years, but we did have a live service, www.fridgemountain.com, based on that code, but neglected to promote it)

like image 115
NealeU Avatar answered Oct 25 '22 06:10

NealeU