Google App Engine Entity Manager Configuration with Spring 3.0

I'm trying to write a Spring configuration for some basic Google App Engine services. In particular for the EntityManagerFactory and Entity Manager.

To create an EntityManagerFactory from Java code:

EntityManagerFactory emfInstance = javax.persistence.Persistence
    .createEntityManagerFactory("transactions-optional");

Which I would translate as:

<bean id="entityManagerFactory" class="javax.persistence.Persistence" 
    factory-method="createEntityManagerFactory" scope="singleton">
    <constructor-arg value="transactions-optional"/> 
</bean>

And every time I need an EntityManager

EntityManager em = emfInstance.get().createEntityManager(); 

But I don't know how to tell to apply the factory method to the previously created factory.

<bean id="entityManagerProto" 
    factory-method="createEntityManager" scope="prototype"/>

Anyone knows? Thanks.

Answers


You can use existing bean as a factory as follows:

<bean id="entityManagerProto"
    factory-bean = "entityManagerFactory"
    factory-method="createEntityManager" scope="prototype"/> 

Also, I'm not sure whether it would work on GAE, but perhaps it would be better to use LocalEntityManagerFactoryBean instead, and get EntityManager injected with @PersistenceContext.


Need Your Help

how to add an initial view in Xcode4 for iPhone app

iphone ios xcode4 uiviewcontroller

My game app presently has a single ViewController and XIB for playing game.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.