Showing posts with label DAO. Show all posts
Showing posts with label DAO. Show all posts

Saturday, 21 November 2015

Spring Data

Spring Data it is useful framework but in my case sometimes it is too easy. Two years ago, when I worked in some company, my colleague wrote some template of framework like this.

It also have generic implementation for a CRUD operation but you have to write implementation for other types of operations. It is one another class which you have to write. It is easy but it doesn't enforce any convention of methods name.

Other huge advantage is resolving of types returning in methods. Every type has it's own meaning. Ex. You can receive a entity or a Optional<Entity> type. When it is looked for list of elements, there is more options, ex. Stream (JDK8), List, Set and Page<Entity> type where there is a information about count of all elements.

Monday, 14 September 2015

JPA 2.0

JPA 2.0 has a few useful things like:
  1. API to basic caching
  2. Unify database source parameters, ex username or password
  3. Improve lock modes
  4. Use advanced JPQL language to create queries
  5. Extends presisting API

ResultSet by Hibernate

In hibernate you can use 3 types of Scrollable ResultSet:
  1. TYPE_SCROLL_INSENSITIVE - it is possible to get selected row of data and retrieve data forward and backward. There is not sensitive for external changes in db, so as I got to know refresh is impossible.
  2. TYPE_SCROLL_SENSITIVE - the same as above but it is sensitive for external changes in db. After calling refresh you get new entity from db.
  3. TYPE_FORWARD_ONLY - it is possible to get data only forward order, you can't get selected row. It is necessary to go in loop by next method.