<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.11" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Using JPA in Spring without referencing Spring</title>
	<link>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/</link>
	<description>The voice of SpringSource</description>
	<pubDate>Thu, 21 Aug 2008 19:26:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.11</generator>

	<item>
		<title>by: Julien</title>
		<link>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-115178</link>
		<pubDate>Wed, 30 Jul 2008 14:05:43 +0000</pubDate>
		<guid>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-115178</guid>
					<description>With this example I'm interesting to know how you could manage some error, like some duplicate entry that you would try to make a retry on the entity but with an other generated value for the unique property...  I tryed some aop interception or to catch some errors on my side but this get me some problems and put transactions errors...

Do you have any idea on how to manage such errors ?

Thanks

Julien</description>
		<content:encoded><![CDATA[<p>With this example I&#039;m interesting to know how you could manage some error, like some duplicate entry that you would try to make a retry on the entity but with an other generated value for the unique property&#8230;  I tryed some aop interception or to catch some errors on my side but this get me some problems and put transactions errors&#8230;</p>
<p>Do you have any idea on how to manage such errors ?</p>
<p>Thanks</p>
<p>Julien
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Juergen Hoeller</title>
		<link>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-111518</link>
		<pubDate>Thu, 03 Jul 2008 13:06:07 +0000</pubDate>
		<guid>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-111518</guid>
					<description>Yes, this is thread-safe, since the injected EntityManager is actually a shared EntityManager proxy that will transparently delegate to the actual thread-bound EntityManager resource in the background.

In other words, any "xxx" call on that EntityManager proxy actually translates to a sort of "entityManagerFactory.getCurrentEntityManager().xxx" call at runtime.

This style is actually defined by the JPA specification; we just adapted it into the Spring environment.

Juergen</description>
		<content:encoded><![CDATA[<p>Yes, this is thread-safe, since the injected EntityManager is actually a shared EntityManager proxy that will transparently delegate to the actual thread-bound EntityManager resource in the background.</p>
<p>In other words, any &#034;xxx&#034; call on that EntityManager proxy actually translates to a sort of &#034;entityManagerFactory.getCurrentEntityManager().xxx&#034; call at runtime.</p>
<p>This style is actually defined by the JPA specification; we just adapted it into the Spring environment.</p>
<p>Juergen
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Martin</title>
		<link>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-111210</link>
		<pubDate>Tue, 01 Jul 2008 07:39:20 +0000</pubDate>
		<guid>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-111210</guid>
					<description>Hi,

is the solution with @PersistenceContext demonstrated above thread-safe? As far as I know in Spring a bean is a singleton per default. What happens if two or more threads call methods of the injected entityManager in parallel? 

Thanks.
Martin</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>is the solution with @PersistenceContext demonstrated above thread-safe? As far as I know in Spring a bean is a singleton per default. What happens if two or more threads call methods of the injected entityManager in parallel? </p>
<p>Thanks.<br />
Martin
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Iwein Fuld</title>
		<link>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-100354</link>
		<pubDate>Mon, 10 Mar 2008 13:09:49 +0000</pubDate>
		<guid>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-100354</guid>
					<description>The problems with loading multiple persistence units are addressed in Spring 2.5 by the PersistenceUnitManager check out the documentation on this, for the full story. http://static.springframework.org/spring/docs/2.5.x/reference/orm.html#orm-jpa.</description>
		<content:encoded><![CDATA[<p>The problems with loading multiple persistence units are addressed in Spring 2.5 by the PersistenceUnitManager check out the documentation on this, for the full story. <a href="http://static.springframework.org/spring/docs/2.5.x/reference/orm.html#orm-jpa." rel="nofollow">http://static.springframework.org/spring/docs/2.5.x/reference/orm.html#orm-jpa.</a>
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Giuseppe Schiavo</title>
		<link>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-86265</link>
		<pubDate>Tue, 08 Jan 2008 21:40:53 +0000</pubDate>
		<guid>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-86265</guid>
					<description>I wish I could delete my previous comment.
My code is working fine now based on what explained in this article. I had to struggle with the configuration a little but I have gained better understanding of the Spring framework. Thank you</description>
		<content:encoded><![CDATA[<p>I wish I could delete my previous comment.<br />
My code is working fine now based on what explained in this article. I had to struggle with the configuration a little but I have gained better understanding of the Spring framework. Thank you
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: carol mcdonald</title>
		<link>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-85646</link>
		<pubDate>Mon, 07 Jan 2008 15:24:28 +0000</pubDate>
		<guid>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-85646</guid>
					<description>Have you tried this with Glassfish V2? I get the following error:
javax.el.ELException: org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException: Exception Description: Cannot use an EntityTransaction while using JTA.
I think the problem is that the JpaTransactionManager does not use JTA ?</description>
		<content:encoded><![CDATA[<p>Have you tried this with Glassfish V2? I get the following error:<br />
javax.el.ELException: org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException: Exception Description: Cannot use an EntityTransaction while using JTA.<br />
I think the problem is that the JpaTransactionManager does not use JTA ?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Giuseppe Schiavo</title>
		<link>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-82411</link>
		<pubDate>Thu, 27 Dec 2007 17:44:41 +0000</pubDate>
		<guid>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-82411</guid>
					<description>I think you should provide a downloadable working examaples in your articles. The theory is ok but when we try what you suggest IT DOES NOT WORK because there is alway some piece missing or incomplete!</description>
		<content:encoded><![CDATA[<p>I think you should provide a downloadable working examaples in your articles. The theory is ok but when we try what you suggest IT DOES NOT WORK because there is alway some piece missing or incomplete!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: JC</title>
		<link>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-16080</link>
		<pubDate>Mon, 19 Mar 2007 17:43:45 +0000</pubDate>
		<guid>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-16080</guid>
					<description>I have implemented this in a project but am running into a strange issue.  Everything works great until I try and delete.  When I try that I get the following exception:

java.lang.IllegalArgumentException: Removing a detached instance com.jc.dao.entity.Story#1
	at org.hibernate.ejb.event.EJB3DeleteEventListener.performDetachedEntityDeletionCheck(EJB3DeleteEventListener.java:47)
	at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:75)
	at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:49)
	at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:766)
	at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:744)
	at org.hibernate.ejb.AbstractEntityManagerImpl.remove(AbstractEntityManagerImpl.java:245)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:176)
	at $Proxy15.remove(Unknown Source)

For frame of reference I'm using a generic DAO similar to an early poster.  This generic DAO has all the basic CRUD operations.  Add, Update and Retrieve all work just fine, it's simply the delete that fails.

I've searched and it seem that this has something to do w/ my transactions though I can't (though experimentation) track it down.  I was wondering if anyone else has see this behavior and found a resolution.

Thanks in advance for any help.</description>
		<content:encoded><![CDATA[<p>I have implemented this in a project but am running into a strange issue.  Everything works great until I try and delete.  When I try that I get the following exception:</p>
<p>java.lang.IllegalArgumentException: Removing a detached instance com.jc.dao.entity.Story#1<br />
	at org.hibernate.ejb.event.EJB3DeleteEventListener.performDetachedEntityDeletionCheck(EJB3DeleteEventListener.java:47)<br />
	at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:75)<br />
	at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:49)<br />
	at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:766)<br />
	at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:744)<br />
	at org.hibernate.ejb.AbstractEntityManagerImpl.remove(AbstractEntityManagerImpl.java:245)<br />
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br />
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br />
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br />
	at java.lang.reflect.Method.invoke(Method.java:585)<br />
	at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:176)<br />
	at $Proxy15.remove(Unknown Source)</p>
<p>For frame of reference I&#039;m using a generic DAO similar to an early poster.  This generic DAO has all the basic CRUD operations.  Add, Update and Retrieve all work just fine, it&#039;s simply the delete that fails.</p>
<p>I&#039;ve searched and it seem that this has something to do w/ my transactions though I can&#039;t (though experimentation) track it down.  I was wondering if anyone else has see this behavior and found a resolution.</p>
<p>Thanks in advance for any help.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Dave</title>
		<link>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-11273</link>
		<pubDate>Fri, 09 Feb 2007 15:08:59 +0000</pubDate>
		<guid>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-11273</guid>
					<description>Disregard last question: found visibility on base class function was not set correctly.  All is working well.

Thank you</description>
		<content:encoded><![CDATA[<p>Disregard last question: found visibility on base class function was not set correctly.  All is working well.</p>
<p>Thank you
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Dave</title>
		<link>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-11180</link>
		<pubDate>Thu, 08 Feb 2007 23:04:42 +0000</pubDate>
		<guid>http://blog.springsource.com/main/2006/08/07/using-jpa-in-spring-without-referencing-spring/#comment-11180</guid>
					<description>A comment and a question:

First, thank you for this post. Nice to see all of this put together with the examples.

My comment:  I struggled with the same issue that vatel did regarding beanFactory v.s. ApplicationContext.  I think it is worth noting in your presentation that post processors like the PersistenceAnnotationBeanPostProcessor only get called if beans are loaded using the ApplicationContext.  I'm fairly new to spring, so maybe this is commonly understood, and I missed it.

My Question:  I am implementing a generic DAO implementation in which all of my DAO's inherit from a common base class (GenericDAO).  I would like to keep the EntityManager in the base class to be used by all subclasses.  I have tried implementing this with the @PersistenContext annotation in the base class, however, PersistenceAnnotationBeanPostProcessor does not seem to inject the entity manager to the base class.  If I create a subclass attribute/function and annotate this, then the injection works fine.  Do I have a configuration issue, or is this a limitation in spring?

Any input would be greatly appreciated.</description>
		<content:encoded><![CDATA[<p>A comment and a question:</p>
<p>First, thank you for this post. Nice to see all of this put together with the examples.</p>
<p>My comment:  I struggled with the same issue that vatel did regarding beanFactory v.s. ApplicationContext.  I think it is worth noting in your presentation that post processors like the PersistenceAnnotationBeanPostProcessor only get called if beans are loaded using the ApplicationContext.  I&#039;m fairly new to spring, so maybe this is commonly understood, and I missed it.</p>
<p>My Question:  I am implementing a generic DAO implementation in which all of my DAO&#039;s inherit from a common base class (GenericDAO).  I would like to keep the EntityManager in the base class to be used by all subclasses.  I have tried implementing this with the @PersistenContext annotation in the base class, however, PersistenceAnnotationBeanPostProcessor does not seem to inject the entity manager to the base class.  If I create a subclass attribute/function and annotate this, then the injection works fine.  Do I have a configuration issue, or is this a limitation in spring?</p>
<p>Any input would be greatly appreciated.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
