简体   繁体   中英

Java + Spring + hibernate : Dao implementation that is about to change in the future

I'm currently developing a web server with spring 3 and hibernate 4.

in my server i have the following interfaces:

  1. GenericDao
  2. UserDao extends GenericDao
  3. ProductDao extends GenericDao
  4. ... more daos here

and 3 implementations:

  1. HibernateGenericDaoImpl
  2. HibernateUserDaoImpl
  3. HibernateProductDaoImpl
  4. ....more Hibernate daos impl here

In the future we are considering very highly to migrate to a NO-SQL db (maybe couchDB). My questions is:

"since no-sql has nothing to do with orm, will i need to actually replace all the daos impl in my project?! (there could be alot) isn't there a more generic way?"

thanks!

What about using JPARepository : look at http://www.springsource.org/spring-data/jpa

CrudRepository are very usefull and save a lot of time. Look at the jpa-spring documentation too You define a sub-interface of CrudRepository for store entity class objects. CrudRepository define for you the crud service And you can add in your interface a method like "findTicketByExpireDateBefore(Date date)" then spring will use the naming convention to build the implentation of the requete If the requete is more complexe you can use the @Query annotation to write it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM