<?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/">
<channel>
	<title>Comments on: 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>
	<description>thoughts on Java enterprise software development</description>
	<pubDate>Sun, 01 Aug 2010 06:14:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.12-alpha</generator>

	<item>
		<title>by: Chris</title>
		<link>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-189</link>
		<pubDate>Mon, 22 Feb 2010 19:08:51 +0000</pubDate>
		<guid>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-189</guid>
					<description>Couldn't get this working properly. All the time I ended up with either Statements being committed individually via autocommit or not at all or XAExceptions. Then I tried Atomikos essentials transactionmanager together with their datasource (nonjta version). I got that working all right. Just the other day I found a much easier solution to this:Spring's TransactionAwareDataSourceProxy class. The problem all the time was that the datasource was not properly transaction aware (like it is in a jee environment). Just wrap your datasource with TransactionAwareDataSourceProxy and pass it to the LocalContainerEntityManagerFactory via the dataSource property:&lt;code&gt;&#60;bean id="dataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy"&#62;&#60;constructor -arg ref="dbcpDataSource" /&#62; &#60;/bean&#62;&#60;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&#62;&#60;property name="dataSource" ref="dataSource"/&#62;.......&lt;/code&gt;No need to enrich the PersistenceUnitInfo or use jndi at allcheers</description>
		<content:encoded><![CDATA[Couldn't get this working properly. All the time I ended up with either Statements being committed individually via autocommit or not at all or XAExceptions. Then I tried Atomikos essentials transactionmanager together with their datasource (nonjta version). I got that working all right. Just the other day I found a much easier solution to this:Spring's TransactionAwareDataSourceProxy class. The problem all the time was that the datasource was not properly transaction aware (like it is in a jee environment). Just wrap your datasource with TransactionAwareDataSourceProxy and pass it to the LocalContainerEntityManagerFactory via the dataSource property:<code>&lt;bean id="dataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy"&gt;&lt;constructor -arg ref="dbcpDataSource" /&gt; &lt;/bean&gt;&lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;&lt;property name="dataSource" ref="dataSource"/&gt;.......</code>No need to enrich the PersistenceUnitInfo or use jndi at allcheers]]></content:encoded>
				</item>
	<item>
		<title>by: Harpritt</title>
		<link>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-114</link>
		<pubDate>Fri, 06 Nov 2009 23:04:16 +0000</pubDate>
		<guid>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-114</guid>
					<description>Cheers for the article Erich.... worked a treat!. Any ideas on Colins duplicate tables ?</description>
		<content:encoded><![CDATA[Cheers for the article Erich.... worked a treat!. Any ideas on Colins duplicate tables ?]]></content:encoded>
				</item>
	<item>
		<title>by: Alexandre</title>
		<link>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-88</link>
		<pubDate>Sat, 28 Feb 2009 20:27:10 +0000</pubDate>
		<guid>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-88</guid>
					<description>What a big configuration file! Anybody could try another configuration that works ??!?!?!??</description>
		<content:encoded><![CDATA[What a big configuration file! Anybody could try another configuration that works ??!?!?!??]]></content:encoded>
				</item>
	<item>
		<title>by: Colin Smith</title>
		<link>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-80</link>
		<pubDate>Sun, 04 Jan 2009 14:28:42 +0000</pubDate>
		<guid>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-80</guid>
					<description>Thanks Erich, after some trial and error I got it working. I defined 2 persistenceUnits in my persistence.xml and pointed each entityManagerFactory to its appropriate persistenceUnit using the "persistenceUnitName" property. The only slightly strange side effect is if I use hibernate's generate ddl option it creates tables in both databases!</description>
		<content:encoded><![CDATA[Thanks Erich, after some trial and error I got it working. I defined 2 persistenceUnits in my persistence.xml and pointed each entityManagerFactory to its appropriate persistenceUnit using the "persistenceUnitName" property. The only slightly strange side effect is if I use hibernate's generate ddl option it creates tables in both databases!]]></content:encoded>
				</item>
	<item>
		<title>by: admin</title>
		<link>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-78</link>
		<pubDate>Thu, 01 Jan 2009 07:36:32 +0000</pubDate>
		<guid>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-78</guid>
					<description>hi colin, you have to make sure that the EntityManagerFactory beans have unique names, use a prefix similar to the way i did it with the datasource beans to define more than one EntityManagerFactory. i used two EntityManagerFactory beans with different names for my last project and had nor problems.</description>
		<content:encoded><![CDATA[hi colin, you have to make sure that the EntityManagerFactory beans have unique names, use a prefix similar to the way i did it with the datasource beans to define more than one EntityManagerFactory. i used two EntityManagerFactory beans with different names for my last project and had nor problems.]]></content:encoded>
				</item>
	<item>
		<title>by: Colin</title>
		<link>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-77</link>
		<pubDate>Tue, 30 Dec 2008 14:57:41 +0000</pubDate>
		<guid>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-77</guid>
					<description>Hi Erich, thanks a lot for your post. I've been trying to use it as the basis for making my JPA application talk to 2 databases (as you suggest at the end of your post, by adding a EntityManagerFactory for the second XA datasource). It seems that is not allowed, the error I get is...org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2 at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:514) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:473) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:599) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:570) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:180) at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:105) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessAfterInstantiation(PersistenceAnnotationBeanPostProcessor.java:308) ... 51 more</description>
		<content:encoded><![CDATA[Hi Erich, thanks a lot for your post. I've been trying to use it as the basis for making my JPA application talk to 2 databases (as you suggest at the end of your post, by adding a EntityManagerFactory for the second XA datasource). It seems that is not allowed, the error I get is...org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2 at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:514) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:473) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:599) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:570) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:180) at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:105) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessAfterInstantiation(PersistenceAnnotationBeanPostProcessor.java:308) ... 51 more]]></content:encoded>
				</item>
	<item>
		<title>by: admin</title>
		<link>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-74</link>
		<pubDate>Wed, 10 Dec 2008 13:25:14 +0000</pubDate>
		<guid>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-74</guid>
					<description>hi guillaume, you are right, according to the Javadoc the LocalContainerEntityManagerFactoryBean.setDataSource() property should not be necessary/set. can't remember why i set it, probably cos i wanted the LocalContainerEntityManagerFactoryBean configuration to work both for non-JTA and JTA datasources. it doesn't seem to cause any problems though. regarding JNDI, please also have a look at the XBean variant described at the end of the post. it allows bootstrapping a standalone JNDI registry and keeps the configuration closer to the standard. guess instead of the JtaPersistenceUnitPostProcessor one could also implement a custom PersistenceUnitManager extending the DefaultPersistenceUnitManager and setting it via LocalContainerEntityManagerFactoryBean.setPersistenceUnitManager().</description>
		<content:encoded><![CDATA[hi guillaume, you are right, according to the Javadoc the LocalContainerEntityManagerFactoryBean.setDataSource() property should not be necessary/set. can't remember why i set it, probably cos i wanted the LocalContainerEntityManagerFactoryBean configuration to work both for non-JTA and JTA datasources. it doesn't seem to cause any problems though. regarding JNDI, please also have a look at the XBean variant described at the end of the post. it allows bootstrapping a standalone JNDI registry and keeps the configuration closer to the standard. guess instead of the JtaPersistenceUnitPostProcessor one could also implement a custom PersistenceUnitManager extending the DefaultPersistenceUnitManager and setting it via LocalContainerEntityManagerFactoryBean.setPersistenceUnitManager().]]></content:encoded>
				</item>
	<item>
		<title>by: Guillaume</title>
		<link>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-73</link>
		<pubDate>Wed, 10 Dec 2008 10:36:36 +0000</pubDate>
		<guid>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-73</guid>
					<description>Hi Erich, nice post, especially the part of how to configure the JTA datasource via Spring without binding directly to the Jndi context. However I wonder why you set anyway the property datasource in the LocalContainerEntityManagerFactoryBean ? Reading spring documentation, this property is seen - JPA speaking - as a not JTA datasource, so it's conflicting with the configuration of the datasource via the JtaPersistenceUnitPostProcessor .</description>
		<content:encoded><![CDATA[Hi Erich, nice post, especially the part of how to configure the JTA datasource via Spring without binding directly to the Jndi context. However I wonder why you set anyway the property datasource in the LocalContainerEntityManagerFactoryBean ? Reading spring documentation, this property is seen - JPA speaking - as a not JTA datasource, so it's conflicting with the configuration of the datasource via the JtaPersistenceUnitPostProcessor .]]></content:encoded>
				</item>
	<item>
		<title>by: vitor</title>
		<link>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-72</link>
		<pubDate>Fri, 05 Dec 2008 04:47:50 +0000</pubDate>
		<guid>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-72</guid>
					<description>Hi Erich, nice post!When initially building an application using spring + jpa + hibernate I saw your post and, even though I am not using JTA (I am using JpaTransactionManager), I used some of the configurations shown here.Now I am running some performance tests to check if I am using the right configuration, and what took my attention was the JtaPersistenceUnitPostProcessor described here.Basically I am using two configurations:(1) setting the dataSource inside JtaPersistenceUnitPostProcessor like in this post(2) setting dataSource directly into LocalContainerEntityManagerFactoryBean, and not using JtaPersistenceUnitPostProcessor at all.When using org.springframework.jdbc.datasource.DriverManagerDataSource as a data source, the results for both configuration were quite the same. Both took around 255 seconds to complete.However, when using com.mchange.v2.c3p0.ComboPooledDataSource as a data source, the result were really different.For configuration (1) I got 28 seconds, while in configuration (2) it took 75 seconds.Your configuration is almost 3 times faster than not using JtaPersistenceUnitPostProcessor.I ran these tests many times, and results were always the same.Do you have any idea why the results I got were so different??I am actually asking this to know better the internals of spring transaction management, so that I can better tune my system, and I can find any information about persistenceUnitPostProcessors.Regards,Vitor.</description>
		<content:encoded><![CDATA[Hi Erich, nice post!When initially building an application using spring + jpa + hibernate I saw your post and, even though I am not using JTA (I am using JpaTransactionManager), I used some of the configurations shown here.Now I am running some performance tests to check if I am using the right configuration, and what took my attention was the JtaPersistenceUnitPostProcessor described here.Basically I am using two configurations:(1) setting the dataSource inside JtaPersistenceUnitPostProcessor like in this post(2) setting dataSource directly into LocalContainerEntityManagerFactoryBean, and not using JtaPersistenceUnitPostProcessor at all.When using org.springframework.jdbc.datasource.DriverManagerDataSource as a data source, the results for both configuration were quite the same. Both took around 255 seconds to complete.However, when using com.mchange.v2.c3p0.ComboPooledDataSource as a data source, the result were really different.For configuration (1) I got 28 seconds, while in configuration (2) it took 75 seconds.Your configuration is almost 3 times faster than not using JtaPersistenceUnitPostProcessor.I ran these tests many times, and results were always the same.Do you have any idea why the results I got were so different??I am actually asking this to know better the internals of spring transaction management, so that I can better tune my system, and I can find any information about persistenceUnitPostProcessors.Regards,Vitor.]]></content:encoded>
				</item>
	<item>
		<title>by: quan.le</title>
		<link>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-71</link>
		<pubDate>Fri, 14 Nov 2008 09:45:45 +0000</pubDate>
		<guid>http://erich.soomsam.net/2007/04/24/spring-jpa-and-jta-with-hibernate-and-jotm/#comment-71</guid>
					<description>Thank you very very much, this post is a great help for me.Wish all the best for you</description>
		<content:encoded><![CDATA[Thank you very very much, this post is a great help for me.Wish all the best for you]]></content:encoded>
				</item>
</channel>
</rss>
