<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.12-alpha" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>erich.soomsam.net</title>
	<link>http://erich.soomsam.net</link>
	<description>thoughts on Java enterprise software development</description>
	<pubDate>Thu, 16 Aug 2007 08:11:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.12-alpha</generator>
	<language>en</language>
			<item>
		<title>presentation on business process management</title>
		<link>http://erich.soomsam.net/2007/07/21/business-process-management/</link>
		<comments>http://erich.soomsam.net/2007/07/21/business-process-management/#comments</comments>
		<pubDate>Sat, 21 Jul 2007 18:03:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category>bpm</category>

		<guid isPermaLink="false">http://erich.soomsam.net/2007/07/21/business-process-management/</guid>
		<description><![CDATA[            this tuesday i held a presentation on business process management at the Java special interest group organized by openForce Information Technology here in vienna. the presentation has been an introduction to the field with details on relevant standards, the different types of BPM [...]]]></description>
			<content:encoded><![CDATA[            <p>this tuesday i held a <a href="./archive/presentation/Business_Process_Management.pdf">presentation on business process management</a> at the Java special interest group organized by <a href="http://www.openforce.com/">openForce Information Technology</a> here in vienna. the presentation has been an introduction to the field with details on relevant standards, the different types of BPM systems available, and the current market situation. furthermore, i presented what to consider when evaluating and integrating a BPM system based on the experience made during the introduction of such a system at the company i am working for.</p>
            <p>there was a lot of positive feedback and a lot of interest as a number of companies are, apparently, considering to migrate their business processes to a commercial BPM product. despite the current interest in BPM systems there seems to be little experience with this technology at the moment. i am glad the presentation went well and i could contribute back to the Java special interest group with my presentation.</p>]]></content:encoded>
			<wfw:commentRss>http://erich.soomsam.net/2007/07/21/business-process-management/feed/</wfw:commentRss>
		</item>
		<item>
		<title>jvmstat</title>
		<link>http://erich.soomsam.net/2007/05/06/jvmstat/</link>
		<comments>http://erich.soomsam.net/2007/05/06/jvmstat/#comments</comments>
		<pubDate>Sun, 06 May 2007 14:17:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category>java</category>

		<guid isPermaLink="false">http://erich.soomsam.net/2007/05/06/jvmstat/</guid>
		<description><![CDATA[            ever had multiple Java background processes running on your system and wondered what is the best way to find out which process is executing a particular Java program? ever had one out of a number of JVMs consuming all memory and/or CPU and [...]]]></description>
			<content:encoded><![CDATA[            <p>ever had multiple Java background processes running on your system and wondered what is the best way to find out which process is executing a particular Java program? ever had one out of a number of JVMs consuming all memory and/or CPU and you simply want to know which program to blame for?</p>
			<p>usually you can track down the Java program being executed by a particular JVM with a detailed look at the output of the <code>ps</code> command on a POSIX compliant OS or by investigating processes with <a href="http://www.microsoft.com/technet/sysinternals/">Sysinternals</a> (recently acquired by Microsoft) <a href="http://www.microsoft.com/technet/sysinternals/ProcessesAndThreads/ProcessExplorer.mspx">Process Explorer</a> on a Microsoft Windows OS.</p>
			<p>yesterday i found out that there is a much easier way to get a list of all JVM processes and the Java program (main class) being executed by each JVM, namely <a href="http://java.sun.com/javase/6/docs/technotes/tools/share/jps.html"><code>jps</code></a>. <code>jps</code> is part of <a href="http://java.sun.com/performance/jvmstat/">jvmstat</a> which is included with J2SE since version 5.0 and available as a separate download for earlier versions. <code>jps</code> lists all JVM processes currently running together with the main class being executed:</p>
			<pre>
# jps -l
10152 sun.tools.jps.Jps
32606 org.jboss.Main
#
			</pre>
			<p>depending on the <a href="http://java.sun.com/javase/6/docs/technotes/tools/share/jps.html#options">command line options</a> used further details of each JVM process (such as the arguments passed to the JVM and the main method) can be revealed. surprisingly <a href="http://elliotth.blogspot.com/2005/01/java-equivalent-of-heap1.html"><code>jps</code> can be written in a few lines of Java</a> using an undocumented API that appeared in J2SE 5.0. the other tools <a href="http://java.sun.com/javase/6/docs/tooldocs/share/jstat.html"><code>jstat</code></a> and <a href="http://java.sun.com/performance/jvmstat/visualgc.html"><code>visualgc</code></a>, also part of jvmstat, might be especially useful to debug performance problems.</p>
			<p>at the moment it looks like the jvmstat features are <a href="http://java.sun.com/performance/jvmstat/faq.html#13">only implemented by the Sun JVM</a>. it would be interesting to see if other JVM implementations provide similar features and command line tools.</p>]]></content:encoded>
			<wfw:commentRss>http://erich.soomsam.net/2007/05/06/jvmstat/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Spring, JPA, and JTA with Hibernate and JOTM</title>
		<link>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/</link>
		<comments>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comments</comments>
		<pubDate>Tue, 24 Apr 2007 19:35:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category>java</category>

		<category>spring</category>

		<category>hibernate</category>

		<guid isPermaLink="false">http://erich.soomsam.net/2007/04/24/spring-jpa-hibernate-jta-and-jotm/</guid>
		<description><![CDATA[            have been struggling for a couple of hours today to modify a Spring JPA configuration with a single datasource, Hibernate as the JPA provider and the JpaTransactionManager to a configuration with two XA datasources, Hibernate as the JPA provider, and the JtaTransactionManager with [...]]]></description>
			<content:encoded><![CDATA[            <p>have been struggling for a couple of hours today to modify a Spring JPA configuration with a single datasource, Hibernate as the JPA provider and the <code>JpaTransactionManager</code> to a configuration with two XA datasources, Hibernate as the JPA provider, and the <code>JtaTransactionManager</code> with JOTM as the standalone JTA provider.</p>
            <p>since the Spring and Hibernate reference manual and Javadoc documentation merely contain a number of hints on how to configure JPA with a JTA transaction manager and <a href="http://forum.springframework.org/showthread.php?t=29674">others</a> <a href="http://forum.springframework.org/archive/index.php/t-23254.html">are</a> <a href="http://forum.springframework.org/archive/index.php/t-26773.html">struggling</a> <a href="http://forum.hibernate.org/viewtopic.php?t=958657">as</a> <a href="http://forum.hibernate.org/viewtopic.php?t=965163">well</a> i decided to post how i finally got it to work.</p>
            <h3>Spring, JPA, Hibernate, and JpaTransactionManager configuration</h3>
            <p>the original configuration with a single datasource, Hibernate as the JPA provider, and the <code>JpaTransactionManager</code> was configured <a href="http://static.springframework.org/spring/docs/2.0.x/reference/orm.html#orm-jpa-setup-lemfb">as</a> <a href="http://static.springframework.org/spring/docs/2.0.x/reference/orm.html#orm-jpa-tx">outlined</a> in the Spring reference manual and various posts on the web. please note that the datasource configuration within the <code>persistence.xml</code> JPA configuration file can be moved to the Spring configuration file as shown in this <a href="http://blog.springframework.com/markf/archives/2006/05/30/getting-started-with-jpa-in-spring-20/">getting started with JPA in Spring 2.0</a> post.</p>
            <samp>persistence.xml</samp>


<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="font-weight: bold; color: black;">?&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;persistence</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/persistence&quot;</span>
             <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
             <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/persistence
                                 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&quot;</span>
             <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- transaction type set to RESOURCE_LOCAL, no JTA support --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;persistence-unit</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;DefaultPersistenceUnit&quot;</span> <span style="color: #000066;">transaction-type</span>=<span style="color: #ff0000;">&quot;RESOURCE_LOCAL&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;properties<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.archive.autodetection&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;class, hbm&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.show_sql&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.format_sql&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.connection.driver_class&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;oracle.jdbc.driver.OracleDriver&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.connection.url&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;jdbc:oracle:thin:@HOST:PORT:SID&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.dialect&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;org.hibernate.dialect.OracleDialect&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.connection.username&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;USERNAME&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.connection.password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;PASSWORD&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/properties<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/persistence-unit<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/persistence<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>



            <samp>spring-context.xml</samp>


<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="font-weight: bold; color: black;">?&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span>
       <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
       <span style="color: #000066;">xmlns:aop</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/aop&quot;</span>
       <span style="color: #000066;">xmlns:tx</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/tx&quot;</span>
       <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                           http://www.springframework.org/schema/tx
                           http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
                           http://www.springframework.org/schema/aop
                           http://www.springframework.org/schema/aop/spring-aop-2.0.xsd&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- enables interpretation of the @Required annotation to ensure that dependency injection actually occures --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>  
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- enables interpretation of the @PersistenceUnit/@PersistenceContext annotations providing convenient
       access to EntityManagerFactory/EntityManager --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- uses the persistence unit defined in the META-INF/persistence.xml JPA configuration file --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;entityManagerFactory&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.jpa.LocalEntityManagerFactoryBean&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- transaction manager for use with a single JPA EntityManagerFactory for transactional data access
       to a single datasource --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;jpaTransactionManager&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.jpa.JpaTransactionManager&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;entityManagerFactory&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;entityManagerFactory&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- enables interpretation of the @Transactional annotation for declerative transaction managment
       using the specified JpaTransactionManager --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;tx:annotation-driven</span> <span style="color: #000066;">transaction-manager</span>=<span style="color: #ff0000;">&quot;jpaTransactionManager&quot;</span> <span style="color: #000066;">proxy-target-class</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- enables interpretation of the @Configurable annotation for domain object dependency injection --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;aop:spring-configured</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/beans<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>



            <h3>Spring, JPA, Hibernate, JtaTransactionManager, and JOTM configuration</h3>
            <p>defining the XA datasources for use with the JOTM transaction manager is <a href="http://www.springframework.org/docs/api/org/springframework/transaction/jta/JotmFactoryBean.html">well documented</a>. merely the fact that the <code>JtaTransactionManager</code> autodetects most JTA transaction managers but not the standalone JOTM transaction manager as documented in the <a href="http://www.springframework.org/docs/api/org/springframework/transaction/jta/JtaTransactionManager.html"><code>JtaTransactionManager</code></a> Javadoc was a bit tricky. a static accessor method is required which is the reason why the <a href="http://www.springframework.org/docs/api/org/springframework/transaction/jta/JotmFactoryBean.html"><code>JotmFactoryBean</code></a> has to be used. the object returned by the <code>JotmFactoryBean</code> implements both the <code>UserTransaction</code> and <code>TransactionManager</code> interface which is detected by the <code>JtaTransactionManager</code> implementation. it is, therefore, sufficient to supply the <code>JotmFactoryBean</code> merely to the <code>userTransaction</code> property of the <code>JtaTransactionManager</code> and not necessary to specify another reference to the <code>transactionManager</code> property.</p>
            <p>once i had the XA datasources and the <code>JtaTransactionManager</code> in place the tricky part was to replace the <code>JpaTransactionManager</code> with the newly defined <code>JtaTransactionManager</code> and to configure the Hibernate JPA provider accordingly to make it participate in JTA transactions. Spring offers <a href="http://static.springframework.org/spring/docs/2.0.x/reference/orm.html#orm-jpa-setup">two ways to setup the JPA EntityManagerFactory</a>. i switched the configuration to the more powerful <code>LocalContainerEntityManagerFactoryBean</code> and moved the properties previously defined in the <code>persistence.xml</code> JPA configuration file to the Spring configuration. furthermore, i replaced the datasource definition with a reference to the XA datasource and implemented a custom <code>PersistenceUnitPostProcessor</code> to be able to specify the JTA capable datasource directly within the Spring configuration file. in addition, setting the <code>jpaPropertyMap</code> property of the <code>LocalContainerEntityManagerFactoryBean</code> correctly to tell Hibernate to use the JOTM JTA transaction manager is necessary.</p>
            <p>please note that a number of <a href="http://www.hibernate.org/hib_docs/v3/reference/en/html/session-configuration.html#configuration-optional">optional configuration properties</a> can be supplied to Hibernate via the <code>jpaPropertyMap</code>. make sure to read and understand the sections on <a href="http://www.hibernate.org/hib_docs/v3/reference/en/html/session-configuration.html#configuration-optional-transactionstrategy">transaction strategy configuration</a>, <a href="http://www.hibernate.org/hib_docs/v3/reference/en/html/session-configuration.html#configuration-j2ee-currentsession">current session context management with JTA</a>, and <a href="http://www.hibernate.org/hib_docs/v3/reference/en/html/architecture.html#architecture-current-session">contextual sessions</a> and set the corresponding configuration properties according to your needs.</p>
            <p>in our current scenario we require JPA access to one of the XA datasources while JDBC is used to access the other datasource. that's the reason why no entity manager factory is defined for the second datasource. it should, however, be possible to adapt the configuration shown below and configure entity manager factories for both XA datasources.</p>
            <samp>persistence.xml</samp>


<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="font-weight: bold; color: black;">?&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;persistence</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/persistence&quot;</span>
             <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
             <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/persistence
                                 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&quot;</span>
             <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- transaction type set to JTA, transaction suspension and XA supported --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;persistence-unit</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SpringConfiguredPersistenceUnit&quot;</span> <span style="color: #000066;">transaction-type</span>=<span style="color: #ff0000;">&quot;JTA&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/persistence<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>



            <samp>spring-context.xml</samp>


<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="font-weight: bold; color: black;">?&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span>
       <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
       <span style="color: #000066;">xmlns:aop</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/aop&quot;</span>
       <span style="color: #000066;">xmlns:tx</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/tx&quot;</span>
       <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                           http://www.springframework.org/schema/tx
                           http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
                           http://www.springframework.org/schema/aop
                           http://www.springframework.org/schema/aop/spring-aop-2.0.xsd&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- enables interpretation of the @Required annotation to ensure that dependency injection actually occures --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>  
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- enables interpretation of the @PersistenceUnit/@PersistenceContext annotations providing convenient
       access to EntityManagerFactory/EntityManager --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- first XA data source --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;bdbInnerDataSource&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.enhydra.jdbc.standard.StandardXADataSource&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;transactionManager&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;jotm&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;driverName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;oracle.jdbc.driver.OracleDriver&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;url&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;jdbc:oracle:thin:@HOST:PORT:SID&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;user&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;USERNAME&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;PASSWORD&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- first XA data source pool --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;bdbDataSource&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.enhydra.jdbc.pool.StandardXAPoolDataSource&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;transactionManager&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;jotm&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;bdbInnerDataSource&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;user&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;USERNAME&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;PASSWORD&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;maxSize&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;4&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- second XA data source --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;bpeInnerDataSource&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.enhydra.jdbc.standard.StandardXADataSource&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;transactionManager&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;jotm&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;driverName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;oracle.jdbc.driver.OracleDriver&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;url&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;jdbc:oracle:thin:@HOST:PORT:SID&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;user&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;USERNAME&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;PASSWORD&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- second XA data source pool --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;bpeDataSource&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.enhydra.jdbc.pool.StandardXAPoolDataSource&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;transactionManager&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;jotm&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;bpeInnerDataSource&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;user&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;USERNAME&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;PASSWORD&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;maxSize&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;4&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- required cos the standalone JOTM transaction manager is not autodetected by the
       JtaTransactionManager cos it requires a static accessor method --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;jotm&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.transaction.jta.JotmFactoryBean&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- supplying the JotmFactoryBean merely to the userTransaction property cos JtaTransactionManager
       autodetects that the object returned by the JotmFactoryBean implements both the
       UserTransaction and the TransactionManager interface --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;jtaTransactionManager&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.transaction.jta.JtaTransactionManager&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;userTransaction&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;jotm&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;allowCustomIsolationLevels&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span>  
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- settings previously specified in the persistence.xml JPA configuration file are now defined with the
       LocalContainerEntityManagerFactoryBean configuration --&gt;</span></span>  
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;entityManagerFactory&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>    
    <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- reference to the XA datasource --&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;bdbDataSource&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- specify Hibernate as the the JPA provider --&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jpaVendorAdapter&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;showSql&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;generateDdl&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;database&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;ORACLE&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;databasePlatform&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;org.hibernate.dialect.OracleDialect&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- configure Hibernate to participate in JTA transactions using the JOTM transaction manager and
         specify further Hibernate specific configuration properties --&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jpaPropertyMap&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;map<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;entry</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.transaction.manager_lookup_class&quot;</span>
               <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;org.hibernate.transaction.JOTMTransactionManagerLookup&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;entry</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.transaction.flush_before_completion&quot;</span>
               <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;entry</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.transaction.auto_close_session&quot;</span>
               <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;entry</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.current_session_context_class&quot;</span>
               <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;jta&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;entry</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.connection.release_mode&quot;</span>
               <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;auto&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>                            
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/map<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- specify that the Hibernate JPA dialect should be used, probably not necessary since 
         HibernateJpaVendorAdapter will most likely set this property --&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jpaDialect&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.jpa.vendor.HibernateJpaDialect&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- custom implementation to enrich the PersistenceUnitInfo read from the persistence.xml
         JPA configuration file with the JTA datasource. specifying the JTA datasource directly in
         the Spring configuration file has the advantage that we can use a direct reference to the
         datasource instead of using a JNDI name as requied by the jta-data-source setting in the
         persistence.xml file --&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;persistenceUnitPostProcessors&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;sample.JtaPersistenceUnitPostProcessor&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jtaDataSource&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;bdbDataSource&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>		
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- enables interpretation of the @Transactional annotation for declerative transaction managment
       using the specified JtaTransactionManager --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;tx:annotation-driven</span> <span style="color: #000066;">transaction-manager</span>=<span style="color: #ff0000;">&quot;jtaTransactionManager&quot;</span> <span style="color: #000066;">proxy-target-class</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- enables interpretation of the @Configurable annotation for domain object dependency injection --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;aop:spring-configured</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/beans<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>



            <samp>sample.JtaPersistenceUnitPostProcessor.java</samp>


<div class="wp_syntax"><div class="code"><pre class="java5"><span style="color: #000000; font-weight: bold;">package</span> sample;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> javax.<span style="color: #006600;">sql</span>.<span style="color: #aaaadd; font-weight: bold;">DataSource</span>;
<span style="color: #000000; font-weight: bold;">import</span> org.<span style="color: #006600;">springframework</span>.<span style="color: #006600;">beans</span>.<span style="color: #006600;">factory</span>.<span style="color: #006600;">annotation</span>.<span style="color: #006600;">Required</span>;
<span style="color: #000000; font-weight: bold;">import</span> org.<span style="color: #006600;">springframework</span>.<span style="color: #006600;">orm</span>.<span style="color: #006600;">jpa</span>.<span style="color: #006600;">persistenceunit</span>.<span style="color: #006600;">MutablePersistenceUnitInfo</span>;
<span style="color: #000000; font-weight: bold;">import</span> org.<span style="color: #006600;">springframework</span>.<span style="color: #006600;">orm</span>.<span style="color: #006600;">jpa</span>.<span style="color: #006600;">persistenceunit</span>.<span style="color: #006600;">PersistenceUnitPostProcessor</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * the {@link JtaPersistenceUnitPostProcessor} enables us to define the JTA capable datasource
 * which should be used by the JPA provider directly as a reference within the Spring configuration
 * file.
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JtaPersistenceUnitPostProcessor <span style="color: #000000; font-weight: bold;">implements</span> PersistenceUnitPostProcessor <span style="color: #66cc66;">&#123;</span>
  <span style="color: #808080; font-style: italic;">/**
   * a reference to the JTA capable datasource which is add to the PersistenceUnitInfo during post
   * processing instead of beeing specified using the &quot;jta-data-source&quot; setting in the persistence.xml
   * configuration file
   */</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #aaaadd; font-weight: bold;">DataSource</span> jtaDataSource;
&nbsp;
  <span style="color: #808080; font-style: italic;">/**
   * enrich the PersistenceUnitInfo read from the persistence.xml configuration file with a reference
   * to the jtaDataSource injected via the Spring configuration. the JTA capable datasource is then
   * used by the LocalContainerEntityManagerFactoryBean to create the EntityManagerFactory
   *
   * @see PersistenceUnitPostProcessor#postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo)
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> postProcessPersistenceUnitInfo<span style="color: #66cc66;">&#40;</span>MutablePersistenceUnitInfo mutablePersistenceUnitInfo<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    mutablePersistenceUnitInfo.<span style="color: #006600;">setJtaDataSource</span><span style="color: #66cc66;">&#40;</span>getJtaDataSource<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/**
   * getter for jtaDataSource
   * 
   * @return the JTA capable datasource supplied via the setter
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #aaaadd; font-weight: bold;">DataSource</span> getJtaDataSource<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> jtaDataSource;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/**
   * setter for jtaDataSource 
   *
   * @param jtaDataSource the JTA capable datasource added to the PersistenceUnitInfo during post processing
   */</span>
  @Required
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setJtaDataSource<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">DataSource</span> jtaDataSource<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">jtaDataSource</span> = jtaDataSource;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>



            <p>if you don't want to implement and use a custom <code>PersistenceUnitPostProcessor</code> you can add the <code>jta-data-source</code> setting to the <code>persistence-unit</code> configuration in the <code>persistence.xml</code> file. add the following snippet and specify the JNDI name to the JTA capable datasource:</p>


<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;jta-data-source<span style="font-weight: bold; color: black;">&gt;</span></span></span>jdbc/bdbDataSource<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/jta-data-source<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>



            <p>you will then have to expose the JTA datasource via JNDI which can be achieved by using the <a href="http://geronimo.apache.org/xbean/">XBean</a> library and adding the following snippet to the <code>spring-context.xml</code> file:</p>


<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;jndiContext&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.xbean.spring.jndi.SpringInitialContextFactory&quot;</span>
      <span style="color: #000066;">factory-method</span>=<span style="color: #ff0000;">&quot;makeInitialContext&quot;</span> <span style="color: #000066;">scope</span>=<span style="color: #ff0000;">&quot;singleton&quot;</span> <span style="color: #000066;">lazy-init</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>                
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;entries&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;map<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;entry</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;jdbc/bdbDataSource&quot;</span> <span style="color: #000066;">value-ref</span>=<span style="color: #ff0000;">&quot;bdbDataSource&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/map<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>



            <p>if you plan to use a JTA transaction manager other than the standalone JOTM transaction manager you will have to adapt the XA datasource configuration, most likely use the autodetect mode of the <code>JtaTransactionManager</code> by removing the <code>JotmFactoryBean</code> (or specifying another factory bean), and define a different <a href="http://www.hibernate.org/hib_docs/reference/en/html/session-configuration.html#jtamanagerlookup">hibernate transaction manager lookup class</a>. for in container deployment you will most likely want to use the <code>JndiObjectFactoryBean</code> to integrate the datasources already configured within the application server into the Spring application context (by simply specifying the JNDI name).</p>]]></content:encoded>
			<wfw:commentRss>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
