<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3864280826745370843</id><updated>2012-02-13T07:02:19.553-08:00</updated><category term='tomcat'/><category term='multiple persistence units'/><category term='jpa'/><category term='spring'/><title type='text'>Turgay's Blog</title><subtitle type='html'>Java &amp; JEE notes</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://turgayzengin.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3864280826745370843/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://turgayzengin.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Turgay Zengin</name><uri>http://www.blogger.com/profile/16643970240778501938</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3864280826745370843.post-1323391371652157203</id><published>2007-09-20T12:26:00.000-07:00</published><updated>2007-09-20T13:19:31.176-07:00</updated><title type='text'>Multiple Persistence Units with Spring, JPA, Tomcat - Update</title><content type='html'>&lt;span style="font-family: arial;"&gt;After making the setup I described in the previous blog entry, I faced an error. One of the databases which was the datasource for one of the persistence units defined, was not accessible at that time, and we were getting errors from Spring, causing the &lt;/span&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style="font-weight: bold;"&gt; @PersistenceContext&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: arial;"&gt; annotations not to be injected at all.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial;"&gt;When the bean called&lt;/span&gt; &lt;span style="font-family:Arial;"&gt;&lt;span style="font-weight: bold;"&gt;org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor&lt;br /&gt;&lt;/span&gt;&lt;span&gt;is defined in Spring application context, Spring was trying to set up all persistence units when even only one of them was accessed for an operation - "Login to the system" use case, for example. When one of the databases was not accessible, the SQLException was causing Spring to give up and not load the other persistence units as well. At that time we were using Spring version 2.0.6.&lt;br /&gt;&lt;br /&gt;Going to Spring support forums for a solution to this problem, I couldn't find any help but saw that Spring 2.1-M4 was released and decided to give it a try. Changing spring jars with the new version, the error disappeared - I guess this issue was resolved in this version of Spring. Now if one database is not accessible, only the DAOs which needs that &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style="font-weight: bold;"&gt; @PersistenceContext&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Arial;"&gt;&lt;span&gt; is affected - other DAOs work as expected.&lt;br /&gt;&lt;br /&gt;So, Spring 2.1-M4 or later should be used when more than one persistence unit will be defined.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3864280826745370843-1323391371652157203?l=turgayzengin.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://turgayzengin.blogspot.com/feeds/1323391371652157203/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3864280826745370843&amp;postID=1323391371652157203' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3864280826745370843/posts/default/1323391371652157203'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3864280826745370843/posts/default/1323391371652157203'/><link rel='alternate' type='text/html' href='http://turgayzengin.blogspot.com/2007/09/multiple-persistence-units-with-spring_20.html' title='Multiple Persistence Units with Spring, JPA, Tomcat - Update'/><author><name>Turgay Zengin</name><uri>http://www.blogger.com/profile/16643970240778501938</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3864280826745370843.post-7235673672839679225</id><published>2007-09-11T13:37:00.000-07:00</published><updated>2007-09-11T15:25:13.962-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='multiple persistence units'/><category scheme='http://www.blogger.com/atom/ns#' term='jpa'/><category scheme='http://www.blogger.com/atom/ns#' term='spring'/><category scheme='http://www.blogger.com/atom/ns#' term='tomcat'/><title type='text'>Multiple Persistence Units with Spring, JPA, Tomcat</title><content type='html'>&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;I was struggling with using Spring and JPA on Tomcat some time ago, but then could not manage and turned to EJB3 and Glassfish for my latest project.&lt;br /&gt;&lt;br /&gt;EJB3 is far better than before, but it is not very easy to manage an application server and an "Enterprise Application". I had 3 projects in Eclipse: The enterprise application project, EJB and web application projects. Also, managing an application server is not as easy as managing Tomcat, considering the small size of my team (2 developers). Development - deployment - testing cycle is not easy, as we have to re-publish our application after every small change to JSP files or Java classes. EJB3 and Glassfish (or any other appserver) is also a powerful combination, but I was missing Spring and Tomcat.&lt;br /&gt;&lt;br /&gt;We were half way through our development, and I decided to give another try to using Spring+JPA under Tomcat. This time, I found a &lt;a href="http://asrijaffar.blogspot.com/2007/02/spring-jpa-tomcat.html"&gt;blog in which this setup was described&lt;/a&gt;. Applying those steps and making some changes, I was successful to make it work and converted the application to Spring+JPA+Tomcat 6 in the weekend! We have more than one persistence units defined. Now we feel much confident that we will finish the project on time.&lt;br /&gt;&lt;br /&gt;Here is what I did:&lt;br /&gt;&lt;br /&gt;- In &lt;span style="font-weight: bold;"&gt;src/META-INF/persistence.xml&lt;/span&gt; define the persistence units:&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;persistence-unit name="pu1" type="RESOURCE_LOCAL"&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style="font-weight: bold;"&gt;....&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/persistence-unit&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;persistence-unit name="pu2" type="RESOURCE_LOCAL"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; ....&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style="font-weight: bold;"&gt;&amp;lt;/persistence-unit&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;- In &lt;span style="font-weight: bold;"&gt;META-INF&lt;/span&gt; folder (under the web application root, not the one in src folder which goes under WEB-INF/classes), create a file called &lt;span style="font-weight: bold;"&gt;context.xml&lt;/span&gt;. The "&lt;span style="font-weight: bold;"&gt;Loader&lt;/span&gt;" definition is necessary for Spring+JPA under Tomcat, and the "&lt;span style="font-weight: bold;"&gt;Resource&lt;/span&gt;" elements define JNDI entries:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;Context&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;  &amp;lt;Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; useSystemClassLoaderAsParent="false" /&amp;gt;&lt;/span&gt;&lt;o:p style="font-weight: bold;"&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-weight: bold;" class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;span style=""&gt;  &lt;/span&gt;&amp;lt;Resource name="jdbc/db1" auth="Container" type="javax.sql.DataSource"&lt;br /&gt;maxActive="10" maxIdle="5" maxWait="15000"&lt;br /&gt;removeAbandoned="true" removeAbandonedTimeout="300" logAbandoned="true"&lt;br /&gt;initialSize="2" minIdle="2" username="username1" password="password1"&lt;br /&gt;driverClassName="oracle.jdbc.driver.OracleDriver"&lt;br /&gt;url="jdbc:oracle:thin:@localhost:1521:xe"/&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-weight: bold;" class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;span style=""&gt;  &lt;/span&gt;&amp;lt;Resource name="jdbc/db2" auth="Container" type="javax.sql.DataSource"&lt;br /&gt;maxActive="10" maxIdle="5" maxWait="15000"&lt;br /&gt;removeAbandoned="true" removeAbandonedTimeout="300" logAbandoned="true"&lt;br /&gt;initialSize="2" minIdle="2" username="username2" password="password2"&lt;br /&gt;driverClassName="oracle.jdbc.driver.OracleDriver"&lt;br /&gt;url="jdbc:oracle:thin:@localhost:1521:xe"/&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/Context&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;- In &lt;span style="font-weight: bold;"&gt;web.xml&lt;/span&gt;, define "&lt;span style="font-weight: bold;"&gt;resource-ref&lt;/span&gt;" entries for db connections:&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;resource-ref&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;  &amp;lt;description&amp;gt;DB Connection 1&amp;lt;/description&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;  &amp;lt;res-ref-name&amp;gt;jdbc/db1&amp;lt;/res-ref-name&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;  &amp;lt;res-type&amp;gt;javax.sql.DataSource&amp;lt;/res-type&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;  &amp;lt;res-auth&amp;gt;Container&amp;lt;/res-auth&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/resource-ref&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;resource-ref&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;  &amp;lt;description&amp;gt;DB Connection 2&amp;lt;/description&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;  &amp;lt;res-ref-name&amp;gt;jdbc/db2&amp;lt;/res-ref-name&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;  &amp;lt;res-type&amp;gt;javax.sql.DataSource&amp;lt;/res-type&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;  &amp;lt;res-auth&amp;gt;Container&amp;lt;/res-auth&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/resource-ref&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;- Spring ContextLoaderListener must also be present in &lt;span style="font-weight: bold;"&gt;web.xml&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;listener&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;listener-class&amp;gt; org.springframework.web.context.ContextLoaderListener&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/listener-class&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/listener&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;- Beans in Spring application context look like:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;!-- JPA annotations bean post processor --&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;!-- Exception translation bean post processor --&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;tx:annotation-driven manager="transactionManager1"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;tx:annotation-driven manager="transactionManager2"&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;bean id="dao1" class="dao.DAO1JPA"&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/bean&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;bean id="dao2" class="dao.DAO2JPA"&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/bean&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;bean id="service1" class="service.Service1Impl"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="dao" ref="dao1"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/bean&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;bean id="service2" class="service.Service2Impl"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="dao" ref="dao2"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/bean&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;bean id="entityManagerFactory1" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="persistenceUnitName" value="pu1"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="dataSource" ref="dataSource1"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="jpaVendorAdapter"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; .... &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="loadTimeWeaver"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;bean class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/property&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/bean&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;bean id="entityManagerFactory2" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="persistenceUnitName" value="pu2"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="dataSource" ref="dataSource2"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="jpaVendorAdapter"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; .... &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="loadTimeWeaver"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;bean class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/property&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/bean&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;bean id="dataSource1" class="org.springframework.jndi.JndiObjectFactoryBean"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="jndiName" value="java:comp/env/jdbc/db1"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/bean&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;bean id="dataSource2" class="org.springframework.jndi.JndiObjectFactoryBean"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="jndiName" value="java:comp/env/jdbc/db2"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/bean&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;bean id="transactionManager1" class="org.springframework.orm.jpa.JpaTransactionManager"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="entityManagerFactory" ref="entityManagerFactory1"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="dataSource" ref="dataSource1"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/bean&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;bean id="transactionManager2" class="org.springframework.orm.jpa.JpaTransactionManager"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="entityManagerFactory" ref="entityManagerFactory2"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;property name="dataSource" ref="dataSource2"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &amp;lt;/bean&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;- Let Spring inject EntityManager instances into DAO classes:&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; @PersistenceContext(unitName = "pu1")&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style="font-weight: bold;"&gt;private EntityManager emPU1;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;- Database jars, spring-tomcat-weaver.jar and toplink-essentials.jar are placed in Tomcat/lib folder. Spring jars (spring.jar, spring-aspects.jar, spring-mock.jar) are placed in WEB-INF/lib.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;- In &lt;span style="font-weight: bold;"&gt;Tomcat6/lib&lt;/span&gt; folder, &lt;span style="font-weight: bold;"&gt;annotations-api.jar&lt;/span&gt; contains classes which causes exceptions. From that jar, delete package "&lt;span style="font-weight: bold;"&gt;javax.persistence&lt;/span&gt;" to get rid of those exceptions. (Found this info &lt;a href="http://forum.springframework.org/showthread.php?p=139952"&gt;here&lt;/a&gt;)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;"&gt;With this setup, develop - deploy - test cycle is much easier now. We also have access to all Spring goodies now: Easy e-mail sending, defining jobs with Quartz, JMX exporter, ....&lt;br /&gt;&lt;br /&gt;(Code and XML formatting is not easy here, or I don't know how to format better on blogger. Any suggestions?)&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3864280826745370843-7235673672839679225?l=turgayzengin.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://turgayzengin.blogspot.com/feeds/7235673672839679225/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3864280826745370843&amp;postID=7235673672839679225' title='51 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3864280826745370843/posts/default/7235673672839679225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3864280826745370843/posts/default/7235673672839679225'/><link rel='alternate' type='text/html' href='http://turgayzengin.blogspot.com/2007/09/multiple-persistence-units-with-spring.html' title='Multiple Persistence Units with Spring, JPA, Tomcat'/><author><name>Turgay Zengin</name><uri>http://www.blogger.com/profile/16643970240778501938</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>51</thr:total></entry></feed>
