That's correct and you shouldn't add PersistenceContext on your methods, only on the private EntityManager em attribute.
In the article it states that you need to annotate a Spring bean with @Transactional and methods/fields with @PersistenceContext in order to provide transaction support and to inject an entity manager. That's correct and you shouldn't add @PersistenceContext on your methods, only on the private EntityManager em attribute. Is there something the defines a bean as a "Spring Bean"?
That's a bean managed by the Spring container (i.e. Spring manages its lifecycle, wires it with other Spring beans, etc). This implies of course that you are creating a Spring container at some point.
I guessed that these belonged in the context. Xml file because the article never specifically said which file is the "application context" file. If this is wrong, please let me know.
This belongs in an application context file which is just an XML file and the name doesn't really matter as long as you tell the Spring container to load it. And actually, that's the big question: how do you run your code? The article runs the sample from a test case which extends a Spring class providing Spring support (by this I mean that it will create the Spring container for you) and allowing to tell Spring which application context file(s) to load (in this case, my-spring-config.
Xml) by providing a getConfigLocations method: package org. Bookguru; import org.springframework.test.jpa. AbstractJpaTests; public class BookInventorySystemTest extends AbstractJpaTests { private BookInventorySystem bookInventorySystem; public void setBookInventorySystem( BookInventorySystem bookInventorySystem) { this.
BookInventorySystem = bookInventorySystem; } protected String getConfigLocations() { return new String {"/my/path/my-spring-config. Xml"}; } } So, how do you run your code?
My code is running as a portlet in Liferay/Tomcat. It's because we're using the Tomcat bundle for Liferay (and not deploying to a JEE container), that I was looking at using Spring as a JPA to provide the injection of the em and transaction management. – sdoca Jun 9 '10 at 21:57 If I had a class that extended a Spring class (which one?) that then creates the Spring container and that class made use of GenericCrudServiceBean, would this also meet the second requirement of Bozho's post?
Would be nice to kill two birds with one stone... – sdoca Jun 9 '10 at 22:06 @sdoca I don't have enough knowledge of portlets and liferay to answer this. – Pascal Thivent Jun 9 '10 at 22:25 Thanks Pascal, I appreciate you taking the time to look at this. – sdoca Jun 9 '10 at 14:53.
In order for a class to be a spring bean it has to be: either mapped as or annotated with @Component, @Service, or similar stereotype annotations not instantiated by you. If you want spring to wire your dependencies, you must let it instantiate your classes. So no new GenericCrudServiceBean() (there are "tricks" to enable dependency injection even when using the new operator, but they are for special cases) In order not to need to instantiate your classes, you must put something "in front" of your controllers and services.
For web-frameworks this would be a Servlet, or addition to the servlet, that handles your classes via the ApplicationContext of spring - in Spring MVC DispatcherServlet is used - in JSF a custom spring ELResolver is used Depending on your framework, look for "X spring integration". For your case - Portlets - spring have the Portlet MVC.
So, if I add to @Service to my class I've met the first requirement. How would I go about meeting the second considering the GenericCrudServiceBean is being used in a portlet deployed on Liferay/Tomcat? When/how would Spring instantiate it?
– sdoca Jun 9 '10 at 22:02 you'd have something to sit in front and intercept requests. For example a dispatcher servlet. Read the relevant parts of the docs.
– Bozho Jun 10 '10 at 11:36 Thanks for the suggestions. I searched for any reference to using Spring and portlets since that's the framework I'm using. It appears to not be supported.
– sdoca Jun 16 '10 at 20:30 @sdoca on the contrary. See my update – Bozho Jun 16 '10 at 20:52.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.