You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Bruno Dusausoy <bd...@yp5.be> on 2010/06/03 15:44:09 UTC

Spring integration

Hi,

First of all I'd like to thank you for this nice piece of work !
Although I'm a new user of OpenEJB I already find it great.

But unfortunately I have some troubles using it as test environment.

What I'm trying to achieve is integration with Spring JUnit transactional
test hierachy[1] for my DAO's.
Integration with C5 Test Support more precisely[2].

I've read the documentation on OpenEJB site, downloaded, read and launched
the examples.
I've also search the mailing-list archives and found the thread named
"Help with OpenEJB3 and Spring IoC" by Jon Carrera.  
I'm still facing a few problems though.

- persistence.xml : I have provider-agnostic persistence.xml. It's because
we plan on deploying in Glassfish but I'd like to test with OpenEJB.
With plain-Spring it's not a problem because the
LocalContainerEntityManagerFactoryBean allows for heavy customisations. 
The resulting EntityManager is then inserted into the JpaTemplate.
However the scenario is different with OpenEJB.
How can I inject a Spring-created EntityManager into OpenEJB ? I've seen
into the documentation that the opposite is currently not possible (unless
using a simple workaround) but I've seen nothing related to Spring ->
OpenEJB. Is it possible ?

- transactions : here it's more a misunderstanding of the whole
transaction process. 
If I give Spring the transaction manager, like this :

    <bean name="TransactionManager"
class="org.apache.geronimo.transaction.manager.GeronimoTransactionManager"/>

    <bean name="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionManager" ref="TransactionManager"/>
    </bean>

Will Spring call the @Transactional annotated test methods - that is, all
test methods by default - within a transaction ?
Will Spring be in charge of all transaction-handling (propagating it to
EJB's) or will it still be OpenEJB in charge ?
Is there an specific configuration I need to write ?

I don't know if this is all clear, I hope it is ;).

Thanks in advance and keep up the good work !

[1]
http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/test/context/junit4/AbstractTransactionalJUnit4SpringContextTests.html
[2] http://code.google.com/p/c5-test-support/
[3] http://www.mail-archive.com/users@openejb.apache.org/msg00641.html
-- 
Bruno Dusausoy
YP5 Software

--
Pensez environnement : limitez l'impression de ce mail.
Please don't print this e-mail unless you really need to.

Re: Spring integration

Posted by Bruno Dusausoy <bd...@yp5.be>.
On Tue, 15 Jun 2010 16:05:04 -0700, David Blevins <da...@visi.com>
wrote:

[...]
> 
> Sorry for responses on the list being a bit slow, we're working quite
> heavily on EJB 3.1 at the moment.
> 
No problem, it's way more important than my question :).
 
> Maybe if you could share some of the motivation why you need Spring to
> hand so much of the transactional work.
> 
Well, as I said, it's because we used to use intensively Carbon5 Test
Support (http://code.google.com/p/c5-test-support/).
It really eases our database testing, allowing for painless database
setup/cleanup, transaction rollback after tests, ...
However, it's based on Spring's testing hierarchy.
That's the reason why I'd like to use Spring/OpenEJB integration.
I guess I'll have to recreate a similar testing hierarchy for OpenEJB.
Unfortunately I'm not as familiar with EJB/OpenEJB as with Spring ... yet
;)

> Does the application that runs in Glassfish use Spring created
> EntityManagers and DataSources rather than the ones created by
Glassfish?
>
No, in production it's all handled by Glassfish itself : no Spring
involved.
 
> If the goal is simply to do things just as would be done in Glassfish
and
> be able to write transactional tests, then maybe check out this example:
> 
>  
http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/transaction-rollback/
>
I'll check it out. Thanks.
 
> Maybe also this one as it uses the same persistence provider as
Glassfish
> uses:
> 
>  
http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/jpa-eclipselink/
> 
> As well it is possible to supply an entirely different persistence.xml
for
> just testing purposes:
> 
>   http://openejb.apache.org/3.0/alternate-descriptors.html
> 
> Hope some of this helps!
>
Sure, it definitely helped. 
Thanks a lot and keep up the excellent work !

Btw, I've read your call for contribution, and if I have enough spare-time
I will definitely help.
But don't take it for granted ;).
 
-- 
Bruno Dusausoy
YP5 Software
--
Pensez environnement : limitez l'impression de ce mail.
Please don't print this e-mail unless you really need to.

Re: Spring integration

Posted by David Blevins <da...@visi.com>.
On Jun 4, 2010, at 12:42 AM, Bruno Dusausoy wrote:

> On Thu, 03 Jun 2010 15:44:09 +0200, Bruno Dusausoy <bd...@yp5.be>
> wrote:
> 
> [...]
> 
> Ok, so I'm thinking of this sequence of initialization :
> 
> - Declaring a DBCP DataSource within Spring (may be not needed since
> OpenEJB also uses DBCP);
> - Creating an EntityManager with LocalContainerEntityManagerFactoryBean,
> so I can tweak the creation of the former;
> - Launching OpenEJB;
> - Getting the transaction manager from OpenEJB and link it to Spring's
> JtaTransactionManager thanks to its reference;
> - Declaring <tx:annotation-driven/> so I can use @Transactional
> annotations in my classes;
> - Injecting the DataSource declared above into OpenEJB (is it needed since
> the EntityManager will have a reference to it ?);
> - Injecting the EntityManager into the EJB's who need it;
> 
> Would this work, and as asked before, will the whole transaction process
> be coherent ?

Sorry for responses on the list being a bit slow, we're working quite heavily on EJB 3.1 at the moment.

Maybe if you could share some of the motivation why you need Spring to hand so much of the transactional work.

Does the application that runs in Glassfish use Spring created EntityManagers and DataSources rather than the ones created by Glassfish?

If the goal is simply to do things just as would be done in Glassfish and be able to write transactional tests, then maybe check out this example:

  http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/transaction-rollback/

Maybe also this one as it uses the same persistence provider as Glassfish uses:

  http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/jpa-eclipselink/

As well it is possible to supply an entirely different persistence.xml for just testing purposes:

  http://openejb.apache.org/3.0/alternate-descriptors.html

Hope some of this helps!


-David


Re: Spring integration

Posted by Bruno Dusausoy <bd...@yp5.be>.
On Thu, 03 Jun 2010 15:44:09 +0200, Bruno Dusausoy <bd...@yp5.be>
wrote:

[...]

Ok, so I'm thinking of this sequence of initialization :

- Declaring a DBCP DataSource within Spring (may be not needed since
OpenEJB also uses DBCP);
- Creating an EntityManager with LocalContainerEntityManagerFactoryBean,
so I can tweak the creation of the former;
- Launching OpenEJB;
- Getting the transaction manager from OpenEJB and link it to Spring's
JtaTransactionManager thanks to its reference;
- Declaring <tx:annotation-driven/> so I can use @Transactional
annotations in my classes;
- Injecting the DataSource declared above into OpenEJB (is it needed since
the EntityManager will have a reference to it ?);
- Injecting the EntityManager into the EJB's who need it;

Would this work, and as asked before, will the whole transaction process
be coherent ?

-- 
Bruno Dusausoy
YP5 Software
--
Pensez environnement : limitez l'impression de ce mail.
Please don't print this e-mail unless you really need to.