[appengine-java] Re: Spring 2.5 Transactions - anyone got this working?

2010-04-03 Thread Carl Ballantyne
Hi Objectuser,

Thanks for the suggestions.

Pointcut is correct (I think so - keep second guessing myself though
trying to implement this). I changed the domain to something generic
when posting the example.

Can you please confirm the following is correct, ie that you inject
the proxy into the transaction manager.

bean id=txManager
class=org.springframework.orm.jdo.JdoTransactionManager
property name=persistenceManagerFactory
ref=persistenceManagerFactoryProxy /
/bean

The Spring 2.5 reference documentation in section 12.3.4 (http://
static.springsource.org/spring/docs/2.5.x/reference/orm.html#orm-jdo)
has only the persistence manager factory. But it looks to me like it
not in the context of using the proxy for transaction management. Some
operations will work if I only inject the persistenceManagerFactory
but then some will not (however all fail for testcases)

I cannot get a testcase to work using spring managed transactions.
Interestingly if I inject just the persistenceManagerFactory into the
txManager bean some operations work but no testcase will work. Setting
up testcases for the datastore is a real pain and I have followed the
directions as per the google doco.

Will try taking out the close methods and see if that makes a
difference.

Will keep bashing my head against this appengine wall.

Cheers,
Carl.


On Mar 31, 2:10 pm, objectuser kevin.k.le...@gmail.com wrote:
 Check your pointcut ... is com.myapp.dao... correct?

 If that's correct, then I don't see anything amiss; it looks really
 good.  Are you even able to setup a test where it works?  Or are you
 doing it from a test?

 Oh, and check the use of pm.close().  That should be taken care of bySpringI 
 think.  I don't do it in my app anyway.

 If those don't work, then I'll looks again.


-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Spring 2.5 Transactions - anyone got this working?

2010-03-31 Thread objectuser
Check your pointcut ... is com.myapp.dao... correct?

If that's correct, then I don't see anything amiss; it looks really
good.  Are you even able to setup a test where it works?  Or are you
doing it from a test?

Oh, and check the use of pm.close().  That should be taken care of by
Spring I think.  I don't do it in my app anyway.

If those don't work, then I'll looks again.

On Mar 30, 3:04 pm, Carl Ballantyne carlballant...@gmail.com wrote:
 Hi objectuser,

 Thanks for the links - very helpful. I have had a look and studied
 them. I am trying to get your example to work but am getting the
 error.

 org.springframework.transaction.CannotCreateTransactionException:
 Could not open JDO PersistenceManager for transaction; nested
 exception is java.lang.IllegalStateException: No JDO
 PersistenceManager bound to thread, and configuration does not allow
 creation of non-transactional one here
 at
 org.springframework.orm.jdo.JdoTransactionManager.doBegin(JdoTransactionManager.java:
 359)

 As far as I can see I have set up everything as should be but am
 missing something obvious because it just will not work. It might be
 something to do with the aop config but I cannot be sure. I have read
 the Spring documentation and your example which are very similar.
 Below is my revised spring xml and I have included example dao code as
 well. If anyone can see what I am doing wrong please correct me.
 Thanks.

 SPRING XML
 -

 bean id=projectDao class=com.myapp.dao.ProjectDaoJdoImpl
         property name=pmf ref=persistenceManagerFactoryProxy /
 /bean

 bean id=persistenceManagerFactory
 class=org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean
         property name=persistenceManagerFactoryName value=transactions-
 optional /
 /bean

 bean id=persistenceManagerFactoryProxy
 class=org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy
 property name=targetPersistenceManagerFactory
 ref=persistenceManagerFactory /
 property name=allowCreate value=false /
 /bean

 bean id=txManager
 class=org.springframework.orm.jdo.JdoTransactionManager
         property name=persistenceManagerFactory
 ref=persistenceManagerFactoryProxy /
 /bean

 tx:advice id=txAdvice transaction-manager=txManager
         tx:attributes
             tx:method name=clearAndCreate propagation=REQUIRED
 rollback-for=Throwable  /
             tx:method name=create propagation=REQUIRED rollback-
 for=Throwable/
             tx:method name=update propagation=REQUIRED rollback-
 for=Throwable /
             tx:method name=delete propagation=REQUIRED rollback-
 for=Throwable /
             tx:method name=* read-only=true/
         /tx:attributes
 /tx:advice

 aop:config
         aop:pointcut id=daoMethods expression=execution(*
 com.myapp.dao.*.*(..))/
     aop:advisor advice-ref=txAdvice pointcut-ref=daoMethods/
 /aop:config

 DAO
 -

 public class ProjectDaoJdoImpl implements ProjectDao {

         private PersistenceManagerFactory pmf;

          public void setPmf(final PersistenceManagerFactory pmf) {
                 this.pmf = pmf;
             }
          private PersistenceManager getPersistenceManager() {
                  return pmf.getPersistenceManager();
             }

          public Project read(Long id) {
                 PersistenceManager pm = getPersistenceManager();

                 try {
                         Project project = pm.getObjectById(Project.class,id);
                         return project;
                 } finally {
                         pm.close();
                 }

         }

 }

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Spring 2.5 Transactions - anyone got this working?

2010-03-30 Thread Carl Ballantyne
Hi objectuser,

Thanks for the links - very helpful. I have had a look and studied
them. I am trying to get your example to work but am getting the
error.

org.springframework.transaction.CannotCreateTransactionException:
Could not open JDO PersistenceManager for transaction; nested
exception is java.lang.IllegalStateException: No JDO
PersistenceManager bound to thread, and configuration does not allow
creation of non-transactional one here
at
org.springframework.orm.jdo.JdoTransactionManager.doBegin(JdoTransactionManager.java:
359)

As far as I can see I have set up everything as should be but am
missing something obvious because it just will not work. It might be
something to do with the aop config but I cannot be sure. I have read
the Spring documentation and your example which are very similar.
Below is my revised spring xml and I have included example dao code as
well. If anyone can see what I am doing wrong please correct me.
Thanks.

SPRING XML
-

bean id=projectDao class=com.myapp.dao.ProjectDaoJdoImpl
property name=pmf ref=persistenceManagerFactoryProxy /
/bean


bean id=persistenceManagerFactory
class=org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean
property name=persistenceManagerFactoryName value=transactions-
optional /
/bean

bean id=persistenceManagerFactoryProxy
class=org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy
property name=targetPersistenceManagerFactory
ref=persistenceManagerFactory /
property name=allowCreate value=false /
/bean


bean id=txManager
class=org.springframework.orm.jdo.JdoTransactionManager
property name=persistenceManagerFactory
ref=persistenceManagerFactoryProxy /
/bean


tx:advice id=txAdvice transaction-manager=txManager
tx:attributes
tx:method name=clearAndCreate propagation=REQUIRED
rollback-for=Throwable  /
tx:method name=create propagation=REQUIRED rollback-
for=Throwable/
tx:method name=update propagation=REQUIRED rollback-
for=Throwable /
tx:method name=delete propagation=REQUIRED rollback-
for=Throwable /
tx:method name=* read-only=true/
/tx:attributes
/tx:advice


aop:config
aop:pointcut id=daoMethods expression=execution(*
com.myapp.dao.*.*(..))/
aop:advisor advice-ref=txAdvice pointcut-ref=daoMethods/
/aop:config

DAO
-

public class ProjectDaoJdoImpl implements ProjectDao {

private PersistenceManagerFactory pmf;

 public void setPmf(final PersistenceManagerFactory pmf) {
this.pmf = pmf;
}
 private PersistenceManager getPersistenceManager() {
 return pmf.getPersistenceManager();
}

 public Project read(Long id) {
PersistenceManager pm = getPersistenceManager();

try {
Project project = pm.getObjectById(Project.class,id);
return project;
} finally {
pm.close();
}

}

}

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Spring 2.5 Transactions - anyone got this working?

2010-03-30 Thread Carl Ballantyne
Sorry as well at the moment I am only trying to get this to work on my
local version of appengine (the SDK). I will look at the workaround
posted at http://code.google.com/p/googleappengine/issues/detail?id=1381
once I have it all working.

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Spring 2.5 Transactions - anyone got this working?

2010-03-28 Thread objectuser
I think you're going to be disappointed.

Spring transactions work in the SDK but not on the GAE host.

Here's how to set them up if you still want to do it (this currently
still works for me in the SDK 1.3.2):

http://objectuser.wordpress.com/2009/06/30/spring-jdo-in-google-app-engine/

But here's the defect that prevents it from working on the host:

http://code.google.com/p/googleappengine/issues/detail?id=1381

On Mar 28, 7:59 am, Carl Ballantyne carlballant...@gmail.com wrote:
 Hi All,

 I have been trying for a while now to get Spring managed transactions
 working on GAE without success. I have searched these forums and the
 web and find a few examples, all slightly different, and none of which
 work for me. I am getting the error class javax.jdo.JDOUserException:
 Transaction is still active. You should always close your transactions
 correctly using commit() or rollback(). This makes total sense to me
 in that Spring is not closing the transaction but I don't understand
 why I am getting it with the following configuration any ideas/
 examples greatly appreciated.

 When I don't use transactions it all works great. But I really need
 the transactions and would love it to be controlled via Spring.

 I am using the latest version of GAE 1.3.2.

 bean id=persistenceManagerFactory
 class=org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean
         property name=persistenceManagerFactoryName value=transactions-
 optional /
 /bean

 bean id=txManager
 class=org.springframework.orm.jdo.JdoTransactionManager
         property name=persistenceManagerFactory
 ref=persistenceManagerFactory /
         property name=jdoDialect ref=dataNucleusJdoDialect/

 /bean

 bean id=dataNucleusJdoDialect
 class=org.datanucleus.springframework.DataNucleusJdoDialect/

 tx:advice id=txAdvice transaction-manager=txManager
         tx:attributes
         tx:method name=clearAndCreate propagation=REQUIRED rollback-
 for=Throwable  /
         tx:method name=create propagation=REQUIRED rollback-
 for=Throwable/
         tx:method name=update propagation=REQUIRED rollback-
 for=Throwable /
         tx:method name=delete propagation=REQUIRED rollback-
 for=Throwable /
         tx:method name=* propagation=NOT_SUPPORTED read-only=true/
         /tx:attributes
 /tx:advice

 aop:config

         aop:advisor pointcut=execution(* com.mydomain.myapp.dao.*.*(..))
 advice-ref=txAdvice/
 /aop:config

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.