File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed
repository/src/main/java/com/iluwatar Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 44
55import org .springframework .context .support .ClassPathXmlApplicationContext ;
66
7+ /**
8+ *
9+ * Repository pattern mediates between the domain and data mapping layers using a collection-like
10+ * interface for accessing domain objects. A system with complex domain model often benefits from
11+ * a layer that isolates domain objects from the details of the database access code and in such
12+ * systems it can be worthwhile to build another layer of abstraction over the mapping layer where
13+ * query construction code is concentrated. This becomes more important when there are a large
14+ * number of domain classes or heavy querying. In these cases particularly, adding this layer helps
15+ * minimize duplicate query logic.
16+ *
17+ * In this example we utilize Spring Data to automatically generate a repository for us from the Person
18+ * domain object. Using the PersonDao we perform CRUD operations on the entity. Underneath we have
19+ * configured in-memory H2 database for which schema is created and dropped on each run.
20+ *
21+ */
722public class App {
823
924 public static void main (String [] args ) {
Original file line number Diff line number Diff line change 44import javax .persistence .GeneratedValue ;
55import javax .persistence .Id ;
66
7+ /**
8+ *
9+ * Person entity
10+ *
11+ */
712@ Entity
813public class Person {
914
@@ -50,5 +55,4 @@ public String toString() {
5055 return "Person [id=" + id + ", name=" + name + ", surname=" + surname
5156 + "]" ;
5257 }
53-
5458}
Original file line number Diff line number Diff line change 55import org .springframework .data .repository .CrudRepository ;
66import org .springframework .stereotype .Repository ;
77
8+ /**
9+ *
10+ * Person repository
11+ *
12+ */
813@ Repository
914public interface PersonDao extends CrudRepository <Person , Long > {
1015
You can’t perform that action at this time.
0 commit comments