File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Using CMP & JPA in same application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Using CMP & JPA in same application" Watch "Using CMP & JPA in same application" New topic
Author

Using CMP & JPA in same application

Rishi Shehrawat
Ranch Hand

Joined: Aug 11, 2010
Posts: 218

Is it possible to use EJB 2.0 CMP & JPA together is same application ? My instictive response was no, however after thinking about it i felt that there are scenarios where this might be required. For example there is an application already written using EJB 2.0 CMP & plan it to move to JPA in a phased manner insterad of big bang. This would mean that for some time JPA & EJB 2.0 CMP will need to co-exist for some time. You are bound to run into issues if both CMP & JPA are being used in same transaction as update made by one might not be visible to other, even though they should be since they are running in same transaction, but again we would face similar issues while using JDBC & JPA together in same transaction.
Sharma Ashutosh
Bartender

Joined: Apr 06, 2001
Posts: 346
Practically speaking you should not be doing so. It can be done but it will be having a lot of overheads and issues.
One such issue that i can think of, when i use Hibernate via Spring's Hibernate template-i have to disable the EJB transactions so that i am using Spring's AOP for declarative transactions.
I won't be doing what you are asking for.


Ashutosh Sharma
SCJP 1.2, SCEA 5, Brainbench certified J2EE Developer, Documentum Certified Professional
Blog : http://scea5-passingpart2and3.blogspot.com/
Rishi Shehrawat
Ranch Hand

Joined: Aug 11, 2010
Posts: 218

Why were you disabling EJB transactions ? Did you encounter any issues.

Declarative transactions using Spring AOP will only apply on beans registered with Spring. Spring beans should be able to pariticipate in transactions started by EJB & it should be vice versa for EJB. This should be only possible if you are using the JTA transaction manager as EJB transactions work only with JTA, unlike Spring which gives us options for using different transaction managers. I agree that it can get very messy having two transaction strategies in an application. This type of scenario again is possible if you are trying to do away with EJB in a phased manner by replacing it with Spring. But for a fresh development it will be a complete no, Either use EJB or Spring, or there could be some special scenarios which Spring cannot support (propogation of transaction context across remote calls).

Coming back to original thread.. I completely agree that using CMP 2.0 & JPA together in fresh deveopment is a complete no, I think it should be done only in very special cases where we are moving from EJB 2.0 to JPA.
Sharma Ashutosh
Bartender

Joined: Apr 06, 2001
Posts: 346
Declarative transactions using Spring AOP will only apply on beans registered with Spring. Spring beans should be able to pariticipate in transactions started by EJB & it should be vice versa for EJB. This should be only possible if you are using the JTA transaction manager as EJB transactions work only with JTA, unlike Spring which gives us options for using different transaction managers. I agree that it can get very messy having two transaction strategies in an application.

Have you tried it on your own? I am using distributed transactions and for that reasons using JTA.
This type of scenario again is possible if you are trying to do away with EJB in a phased manner by replacing it with Spring. But for a fresh development it will be a complete no, Either use EJB or Spring, or there could be some special scenarios which Spring cannot support (propogation of transaction context across remote calls).

I don't want any good single reasons to use both JPA and CMPs together.
I will attribute it to:
1) Bad architecture decisions
2) High maintainability
3) Code duplications as during maintenance time developer might be doing the same thing at multiple places(same as above point)
4) Somebody who has to extend or maintain the code will have hard time(same as above points)

Coming back to original thread.. I completely agree that using CMP 2.0 & JPA together in fresh deveopment is a complete no, I think it should be done only in very special cases where we are moving from EJB 2.0 to JPA.

Anyway why you asked this question at the first place? Is it anything to do with SCEA?
Rishi Shehrawat
Ranch Hand

Joined: Aug 11, 2010
Posts: 218

I have not tried using Spring & EJB to handle transactions in same application, however as per discussions on Spring forum it is possible provided you are using JTA.

I agree with the drawbacks listed, however i feel scenario for co-exist of EJB & Spring can come up if client wants to remove EJB in a phased manner & replace it with Spring, Btw a lot of companies are migrating current EJB apps to Spring.

I came across question on EJB 2.0 CMP & JPA co-existence in Whizlabs simulator.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30894
    
158

Rishi Shehrawat wrote:Is it possible to use EJB 2.0 CMP & JPA together is same application ?

Absolutely. As you noted, an application may develop new components in JPA without rewriting the whole app. As long as the CMP and JPA parts access different tables, I see no problems with this strategy. (If they access the same tables, you run into caching issues.)


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using CMP & JPA in same application