{"id":2578,"date":"2017-11-21T10:29:46","date_gmt":"2017-11-21T10:29:46","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=2578"},"modified":"2017-11-21T10:57:51","modified_gmt":"2017-11-21T10:57:51","slug":"jpa-xml-how-it-is-linked","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/jpa-xml-how-it-is-linked\/","title":{"rendered":"JPA XML How it is Linked?"},"content":{"rendered":"<p>In the Spring Container the underlying persistence unit(oracle, mysql) used can be conveyed in three ways<\/p>\n<ol>\n<li>Dialect<\/li>\n<li>Vendor<\/li>\n<li>Provider<\/li>\n<\/ol>\n<p><strong>Using Dialect in Spring(or)application.xml<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;bean id=&quot;jpaDialect&quot; class=&quot;org.springframework.orm.jpa.vendor.HibernateJpaDialect&quot;\/&gt;\r\n\r\n&lt;bean id=&quot;emf&quot; class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot;&gt;\r\n    &lt;property name=&quot;jpaVendorAdapter&quot;&gt;\r\n        &lt;bean class=&quot;org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter&quot; \/&gt;\r\n    &lt;\/property&gt;\r\n....\r\n&lt;\/bean&gt;\r\n\r\n&lt;bean id=&quot;transactionManager&quot; class=&quot;org.springframework.orm.jpa.JpaTransactionManager&quot;&gt;\r\n    &lt;property name=&quot;entityManagerFactory&quot; ref=&quot;emf&quot;\/&gt;\r\n    &lt;property name=&quot;jpaDialect&quot; ref=&quot;jpaDialect&quot;\/&gt;\r\n&lt;\/bean&gt;\r\n<\/pre>\n<p>We are telling  &#8216;Spring&#8217; to configure a transactionManager whose properties are entityManagerFactory and jpaDialect. Since these properties have to be specific to hibernate these are set according. The entityManagerFactory and jpaDialect are now set specifically to hibernate (or Vendor).<\/p>\n<p><strong>Dialect and Vendor Adapter works together<\/strong><\/p>\n<p><strong>Notes:<\/strong><\/p>\n<ol>\n<li>transactionManager needs entityManagerFactory and jpaDialect<\/li>\n<li>entityManagerFactory &#8211;  defines database related properties <\/li>\n<li>jpaDialect &#8211; JpaDialect is an interface encapsulates certain functionality that standard JPA 1.0 does not offer, such as access to the underlying JDBC Connection.<\/li>\n<\/ol>\n<p><strong>Using Vendor in Spring(or)application.xml<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;property name=&quot;jpaVendorAdapter&quot;&gt;\r\n    &lt;bean class=&quot;org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter&quot; \/&gt;\r\n&lt;\/property&gt;\r\n<\/pre>\n<p><em>the VendorAdapter is injected in to transactionManager along with entityManager<\/em><br \/>\nSince you have provided the class as class=&#8221;org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter&#8221;\/>, this allows Spring to plug in vendor-specific behavior into Spring&#8217;s EntityManagerFactory creators and it serves as single configuration point for all vendor-specific properties.It&#8217;s a custom implementation of spring&#8217;s own JpaVendorAdapter.<\/p>\n<p>The reason it is so is the underlying database differs from application to application based on the needs and the underlying persistence unit which the developer would like to use I.E MySQL, Oracle.<\/p>\n<p><strong>Using Provider persistence-context.xml<\/strong><\/p>\n<persistence-unit name=\"EmployeeService\">\n    <provider>org.hibernate.ejb.HibernatePersistence<\/provider>\n<\/persistence-unit>\n[\/xml]<\/p>\n<p>The <provider> tells spring to use the hibernate provider and the class org.hibernate.ejb.HibernatePersistence is Hibernate EJB3 persistence provider implementation.<\/p>\n<p><strong>Note:<\/strong><br \/>\n<em>Application works just by configuring persistence and provider because the vendor adapter is automatically passed by the persistence provided i.e. HibernatePersistence via the getPersistenceProvider in JpaVendorAdapter.<\/em><\/p>\n<p>Provider + JpaVendorAdapter(Used getPersistenceProvider to get underlying Persistence technology in our case hibernate) -> Works<br \/>\nDialect  + JpaVendorAdapter -> Works<br \/>\nProvider + Dialect   -> Doesn&#8217;t Works<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the Spring Container the underlying persistence unit(oracle, mysql) used can be conveyed in three ways Dialect Vendor Provider Using Dialect in Spring(or)application.xml &lt;bean id=&quot;jpaDialect&quot; class=&quot;org.springframework.orm.jpa.vendor.HibernateJpaDialect&quot;\/&gt; &lt;bean id=&quot;emf&quot; class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot;&gt; &lt;property name=&quot;jpaVendorAdapter&quot;&gt; &lt;bean class=&quot;org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter&quot; \/&gt; &lt;\/property&gt; &#8230;. &lt;\/bean&gt; &lt;bean id=&quot;transactionManager&quot; class=&quot;org.springframework.orm.jpa.JpaTransactionManager&quot;&gt; &lt;property name=&quot;entityManagerFactory&quot; ref=&quot;emf&quot;\/&gt; &lt;property name=&quot;jpaDialect&quot; ref=&quot;jpaDialect&quot;\/&gt; &lt;\/bean&gt; We are telling &#8216;Spring&#8217; to configure a transactionManager&hellip; <a href=\"https:\/\/codethataint.com\/blog\/jpa-xml-how-it-is-linked\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[236],"tags":[],"class_list":["post-2578","post","type-post","status-publish","format-standard","hentry","category-interview-questions-jpa"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=2578"}],"version-history":[{"count":6,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2578\/revisions"}],"predecessor-version":[{"id":2584,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2578\/revisions\/2584"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=2578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=2578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=2578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}