{"id":16833,"date":"2011-12-15T10:00:42","date_gmt":"2011-12-15T08:00:42","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=16833"},"modified":"2013-09-03T21:51:00","modified_gmt":"2013-09-03T18:51:00","slug":"simplifying-data-access-layer-with","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html","title":{"rendered":"Simplifying the Data Access Layer with Spring and Java Generics"},"content":{"rendered":"<h2>1. Overview<\/h2>\n<p>This article will focus on <strong>simplifying the DAO layer<\/strong> by using a single, generified Data Access Object for all entities in the system, which will result in <strong>elegant data access<\/strong>, with no unnecessary clutter or verbosity. <strong><\/strong><\/p>\n<h2>2. The Hibernate and JPA DAOs<\/h2>\n<p>Most production codebases have some kind of DAO layer. Usually the implementation ranges from multiple classes with no abstract base class to some kind of generified class. However, one thing is consistent \u2013 there is <strong>always more then one<\/strong> \u2013 most likely, there is a one to one relation between the DAOs and the entities in the system.<\/p>\n<p>Also, depending on the level of generics involved, the actual implementations can vary from heavily duplicated code to almost empty, with the bulk of the logic grouped in a base abstract class.<\/p>\n<p>These multiple implementations can usually be replaced by <strong>a single parametrized DAO<\/strong> used in such no functionality is lost by taking full advantage of the type safety provided by Java Generics.<\/p>\n<p><strong>Two implementations<\/strong> of this concept are presented next, one for a <strong>Hibernate<\/strong> centric persistence layer and the other focusing on <strong>JPA<\/strong>. These implementation are by no means complete \u2013 only some data access methods are included, but they can be easily be made more thorough.<\/p>\n<h4>2.1.\u00a0The Abstract Hibernate DAO<\/h4>\n<pre class=\" brush:java\">public abstract class AbstractHibernateDao&lt; T extends Serializable &gt; {\r\n\r\n   private Class&lt; T &gt; clazz;\r\n\r\n   @Autowired\r\n   SessionFactory sessionFactory;\r\n\r\n   public final void setClazz( Class&lt; T &gt; clazzToSet ){\r\n      this.clazz = clazzToSet;\r\n   }\r\n\r\n   public T findOne( long id ){\r\n      return (T) getCurrentSession().get( clazz, id );\r\n   }\r\n   public List&lt; T &gt; findAll(){\r\n      return getCurrentSession().createQuery( \"from \" + clazz.getName() ).list();\r\n   }\r\n\r\n   public void create( T entity ){\r\n      getCurrentSession().persist( entity );\r\n   }\r\n\r\n   public void update( T entity ){\r\n      getCurrentSession().merge( entity );\r\n   }\r\n\r\n   public void delete( T entity ){\r\n      getCurrentSession().delete( entity );\r\n   }\r\n   public void deleteById( long entityId ){\r\n      T entity = findOne( entityId );\r\n      delete( entity );\r\n   }\r\n\r\n   protected final Session getCurrentSession(){\r\n      return sessionFactory.getCurrentSession();\r\n   }\r\n}<\/pre>\n<p>The DAO uses the Hibernate API directly, without relying on any Spring templates (such as <em>HibernateTemplate<\/em>). Using of templates, as well as management of the <em>SessionFactory<\/em> which is autowired in the DAO were covered in the <a title=\"The DAO with Spring\" href=\"http:\/\/www.baeldung.com\/2011\/12\/02\/the-persistence-layer-with-spring-3-1-and-hibernate\/\">Hibernate DAO tutorial<\/a>.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h4>2.2. The Generic Hibernate DAO<\/h4>\n<p>Now that the abstract DAO is done, we can implement it just once \u2013 <strong>the generic DAO implementation will become the only implementation<\/strong> needed:<\/p>\n<pre class=\" brush:java\">@Repository\r\n@Scope( BeanDefinition.SCOPE_PROTOTYPE )\r\npublic class GenericHibernateDao&lt; T extends Serializable &gt;\r\n  extends AbstractHibernateDao&lt; T &gt; implements IGenericDao&lt; T &gt;{\r\n   \/\/\r\n}<\/pre>\n<p>First, note that the generic implementation is <strong>itself parametrized<\/strong> \u2013 allowing the client to choose the correct parameter in a case by case basis. This will mean that the clients gets all the benefits of type safety without needing to create multiple artifacts for each entity.<\/p>\n<p>Second, notice the <strong>prototype scope<\/strong> of these generic DAO implementation. Using this scope means that the Spring container will create a new instance of the DAO each time it is requested (including on autowiring). That will allow a service to use multiple DAOs with different parameters for different entities, as needed.<\/p>\n<p>The reason this scope is so important is due to the way Spring initializes beans in the container. Leaving the generic DAO without a scope would mean using the default <strong>singleton scope<\/strong>, which would lead to a single instance of the DAO living in the container. That would obviously be majorly restrictive for any kind of more complex scenario.<\/p>\n<p>The <em>IGenericDao<\/em> is simply an interface for all the DAO methods, so that we can inject our implementation with Spring in (or in whatever is needed):<\/p>\n<pre class=\" brush:java\">public interface IGenericDao&lt;T extends Serializable&gt; {\r\n\r\n   T findOne(final long id);\r\n\r\n   List&lt;T&gt; findAll();\r\n\r\n   void create(final T entity);\r\n\r\n   T update(final T entity);\r\n\r\n   void delete(final T entity);\r\n\r\n   void deleteById(final long entityId);\r\n}<\/pre>\n<h4>2.3. The Abstract JPA DAO<\/h4>\n<pre class=\" brush:java\">public abstract class AbstractJpaDao&lt; T extends Serializable &gt; {\r\n\r\n   private Class&lt; T &gt; clazz;\r\n\r\n   @PersistenceContext\r\n   EntityManager entityManager;\r\n\r\n   public void setClazz( Class&lt; T &gt; clazzToSet ){\r\n      this.clazz = clazzToSet;\r\n   }\r\n\r\n   public T findOne( Long id ){\r\n      return entityManager.find( clazz, id );\r\n   }\r\n   public List&lt; T &gt; findAll(){\r\n      return entityManager.createQuery( \"from \" + clazz.getName() )\r\n       .getResultList();\r\n   }\r\n\r\n   public void save( T entity ){\r\n      entityManager.persist( entity );\r\n   }\r\n\r\n   public void update( T entity ){\r\n      entityManager.merge( entity );\r\n   }\r\n\r\n   public void delete( T entity ){\r\n      entityManager.remove( entity );\r\n   }\r\n   public void deleteById( Long entityId ){\r\n      T entity = getById( entityId );\r\n      delete( entity );\r\n   }\r\n}<\/pre>\n<p>Similar to the Hibernate DAO implementation, the Java Persistence API is used here directly, again not relying on the now <strong>deprecated<\/strong> Spring <em>JpaTemplate<\/em>.<\/p>\n<h4>2.4. The Generic JPA DAO<\/h3>\n<p>Similar to the the Hibernate implementation, the JPA Data Access Object is straighforward as well:<\/p>\n<pre class=\" brush:java\">@Repository\r\n@Scope( BeanDefinition.SCOPE_PROTOTYPE )\r\npublic class GenericJpaDao&lt; T extends Serializable &gt;\r\n extends AbstractJpaDao&lt; T &gt; implements IGenericDao&lt; T &gt;{\r\n   \/\/\r\n}<\/pre>\n<h2>3. Injecting this DAO<\/h2>\n<p>There is now a <strong>single DAO<\/strong> to be injected by Spring; also, the <em>Class<\/em> needs to be specified:<\/p>\n<pre class=\" brush:java\">@Service\r\nclass FooService implements IFooService{\r\n\r\n   IGenericDao&lt; Foo &gt; dao;\r\n\r\n   @Autowired\r\n   public void setDao( IGenericDao&lt; Foo &gt; daoToSet ){\r\n      dao = daoToSet;\r\n      dao.setClazz( Foo.class );\r\n   }\r\n\r\n   \/\/ ...\r\n\r\n}<\/pre>\n<p>Spring <strong>autowires the new DAO insteince using setter injection<\/strong> so that the implementation can be customized with the <em>Class<\/em> object. After this point, the DAO is fully parametrized and ready to be used by the service.<\/p>\n<p>There are of course other ways that the class can be specified for the DAO \u2013 via reflection, or even in XML. My preference is towards this simpler solution because of the improved readability and transparency compared to using reflection.<\/p>\n<h2>4. Conclusion<\/h2>\n<p>This article discussed the <strong>simplification of the Data Access Layer<\/strong> by providing a single, reusable implementation of a generic DAO. This implementation was presented in both a Hibernate and a JPA based environment. The result is a streamlined persistence layer, with no unnecessary clutter.<\/p>\n<p>For a step by step introduction about setting up the Spring context using Java based configuration and the basic Maven pom for the project, see <a title=\"Bootstrapping a web application with Spring\" href=\"http:\/\/www.baeldung.com\/2011\/10\/20\/bootstraping-a-web-application-with-spring-3-1-and-java-based-configuration-part-1\/\" target=\"_blank\">this article<\/a>.<br \/>\n&nbsp;<\/p>\n<div style=\"border: 1px solid #D8D8D8; background: #FAFAFA; width: 100%; padding-left: 5px;\"><b><i>Reference: <\/i><\/b><a href=\"http:\/\/www.baeldung.com\/2011\/12\/08\/simplifying-the-data-access-layer-with-spring-and-java-generics\/\">Simplify the DAO with Spring and Java Generics<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Eugen Paraschiv at the <a href=\"http:\/\/www.baeldung.com\/\">baeldung<\/a> blog.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Overview This article will focus on simplifying the DAO layer by using a single, generified Data Access Object for all entities in the system, which will result in elegant data access, with no unnecessary clutter or verbosity. 2. The Hibernate and JPA DAOs Most production codebases have some kind of DAO layer. Usually the &hellip;<\/p>\n","protected":false},"author":104,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[30],"class_list":["post-16833","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-spring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Simplify the DAO with Spring and Java Generics<\/title>\n<meta name=\"description\" content=\"1. Overview This article will focus on simplifying the DAO layer by using a single, generified Data Access Object for all entities in the system, which\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Simplify the DAO with Spring and Java Generics\" \/>\n<meta property=\"og:description\" content=\"1. Overview This article will focus on simplifying the DAO layer by using a single, generified Data Access Object for all entities in the system, which\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2011-12-15T08:00:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-09-03T18:51:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Eugen Paraschiv\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@http:\/\/twitter.com\/baeldung\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Eugen Paraschiv\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/simplifying-data-access-layer-with.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/simplifying-data-access-layer-with.html\"},\"author\":{\"name\":\"Eugen Paraschiv\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/7a8ad27f4bb34bb3664fda07d3142bc4\"},\"headline\":\"Simplifying the Data Access Layer with Spring and Java Generics\",\"datePublished\":\"2011-12-15T08:00:42+00:00\",\"dateModified\":\"2013-09-03T18:51:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/simplifying-data-access-layer-with.html\"},\"wordCount\":700,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/simplifying-data-access-layer-with.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Spring\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/simplifying-data-access-layer-with.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/simplifying-data-access-layer-with.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/simplifying-data-access-layer-with.html\",\"name\":\"Simplify the DAO with Spring and Java Generics\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/simplifying-data-access-layer-with.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/simplifying-data-access-layer-with.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2011-12-15T08:00:42+00:00\",\"dateModified\":\"2013-09-03T18:51:00+00:00\",\"description\":\"1. Overview This article will focus on simplifying the DAO layer by using a single, generified Data Access Object for all entities in the system, which\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/simplifying-data-access-layer-with.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/simplifying-data-access-layer-with.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/simplifying-data-access-layer-with.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/simplifying-data-access-layer-with.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Simplifying the Data Access Layer with Spring and Java Generics\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/7a8ad27f4bb34bb3664fda07d3142bc4\",\"name\":\"Eugen Paraschiv\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d1e55876feb753ccc6de08d413df2c915e5704dd901010340c1499a7572f8d7a?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d1e55876feb753ccc6de08d413df2c915e5704dd901010340c1499a7572f8d7a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d1e55876feb753ccc6de08d413df2c915e5704dd901010340c1499a7572f8d7a?s=96&d=mm&r=g\",\"caption\":\"Eugen Paraschiv\"},\"sameAs\":[\"http:\\\/\\\/www.baeldung.com\\\/\",\"http:\\\/\\\/www.linkedin.com\\\/in\\\/eugenparaschiv\",\"https:\\\/\\\/x.com\\\/http:\\\/\\\/twitter.com\\\/baeldung\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Eugen-Paraschiv\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Simplify the DAO with Spring and Java Generics","description":"1. Overview This article will focus on simplifying the DAO layer by using a single, generified Data Access Object for all entities in the system, which","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html","og_locale":"en_US","og_type":"article","og_title":"Simplify the DAO with Spring and Java Generics","og_description":"1. Overview This article will focus on simplifying the DAO layer by using a single, generified Data Access Object for all entities in the system, which","og_url":"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2011-12-15T08:00:42+00:00","article_modified_time":"2013-09-03T18:51:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Eugen Paraschiv","twitter_card":"summary_large_image","twitter_creator":"@http:\/\/twitter.com\/baeldung","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Eugen Paraschiv","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html"},"author":{"name":"Eugen Paraschiv","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/7a8ad27f4bb34bb3664fda07d3142bc4"},"headline":"Simplifying the Data Access Layer with Spring and Java Generics","datePublished":"2011-12-15T08:00:42+00:00","dateModified":"2013-09-03T18:51:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html"},"wordCount":700,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Spring"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html","url":"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html","name":"Simplify the DAO with Spring and Java Generics","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2011-12-15T08:00:42+00:00","dateModified":"2013-09-03T18:51:00+00:00","description":"1. Overview This article will focus on simplifying the DAO layer by using a single, generified Data Access Object for all entities in the system, which","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/simplifying-data-access-layer-with.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Simplifying the Data Access Layer with Spring and Java Generics"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/7a8ad27f4bb34bb3664fda07d3142bc4","name":"Eugen Paraschiv","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d1e55876feb753ccc6de08d413df2c915e5704dd901010340c1499a7572f8d7a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d1e55876feb753ccc6de08d413df2c915e5704dd901010340c1499a7572f8d7a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d1e55876feb753ccc6de08d413df2c915e5704dd901010340c1499a7572f8d7a?s=96&d=mm&r=g","caption":"Eugen Paraschiv"},"sameAs":["http:\/\/www.baeldung.com\/","http:\/\/www.linkedin.com\/in\/eugenparaschiv","https:\/\/x.com\/http:\/\/twitter.com\/baeldung"],"url":"https:\/\/www.javacodegeeks.com\/author\/Eugen-Paraschiv"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/16833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/104"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=16833"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/16833\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=16833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=16833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=16833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}