0

Could JSF2 webapplication with EJB3.1 POJOS executed in Tomcat7 without changing the annotations @EJB entity and EJB3.1 related code.

I am using PrimeFaces 3.4.x, Eclipselink JPA 2.3,EJB3.1

And finally I would like to stick to Tomcat7 without using JavaEE6 server, because some customers could not migrate to new Java EE servers due to internal constraints.

But I want native queries and/or criteria queries works well with JPA like joins(left, outer,& inner joins), insert in multiple tables etc.

My journey with GlassFish3.1 was pretty good with primefaces CRUD application with EJB3.1,Eclipselink JPA.

But I could not execute my application because EJB session bean fails to instantiate, without changing the EJBs code.

I am thinking to change the design and source code so that my application runs in Tomcat 7 and Glassfih3.x. May be avoid EJB3.1 and use some thing like DAOs, etc. (i.e. go with J2EE pattern instead of Java EE6 pattern).

EJB3.1 code snippet of UsersController.java:-

@EJB

(1) private com.myapp.session.UsersFacade ejbFacade;

(2) private UsersFacade getFacade() { return ejbFacade; }

// validateUser() method returns a String. (3) String ressult = getFacade().validateUser();

perisistence.xml file

http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> jdbc/ABC false

Sree Rama
  • 1,207
  • 12
  • 25
  • 1
    Tomcat can not directly execute EJB. See http://stackoverflow.com/questions/4304757/how-to-deploy-ejb-3-or-web-application-on-tomcat – nsumer Apr 08 '13 at 17:54
  • nsumer, You should not avoid Tomcat, because of many reasons and one of them could be organization wide policy. I understand the feasibility with Glassfish and as a student project you can easily move to Glassfish. I believe you understand my point please. – Sree Rama Apr 09 '13 at 12:40

3 Answers3

2

Tomcat by default is not a EJB container. To not loose the sleek and simple nature of tomcat but to have a tomcat based EJB container, just use Apache TomEE, it holds the OpenEJB implementation and hence would serve to your need nicely.

maggu
  • 1,201
  • 9
  • 9
  • Maggu, True but I should stick to Tomcat because the production envrionment is Tomcat 7. – Sree Rama Apr 09 '13 at 12:44
  • Maggu, Does Tomy supports the said JPA queries? And I can't avoid tomcat till the production environment uses Tomcat 7. I understand the TomEE is Java EE sertified. – Sree Rama Apr 09 '13 at 12:48
  • Maggu, Would you tell me the application developed using EJB3.1, Eclipselink JPA could easily be migrated to TomEE without changing the source code? – Sree Rama Apr 09 '13 at 12:51
  • TomEE is just Tomcat with Java EE libraries. If you say that you're using EclipseLink, Primefaces and want to use EJB - you're doing it all by yourself while you just can take your code and run it on TomEE (Tomcat on steroids). http://tomee.apache.org/apache-tomee.html – Piotr Nowicki Apr 09 '13 at 13:22
  • @SreeRama - If you cant go away from Tomcat, just bundle the Open EJB, Eclipse Link and prime faces to your application. If there are multiple web applications using this libraries, you can alter SHARED_LOADER configuration in catalina.properties to point to your set of external libraries (primefaces, OpenEJB, Spring, EclipseLink etc) and they will be loaded on tomcat startup. – maggu Apr 10 '13 at 03:00
  • BTW, I see that you are introducing it to a Tomcat Environment. Why dont you go for Spring instead of EJB? Tomcat + Spring + Hibernate + Primefaces is a widely adopted combination. http://stackoverflow.com/questions/1779169/spring-vs-ejb-can-spring-replace-ejb – maggu Apr 10 '13 at 03:06
  • Yes, I am thinking to go for Spring, I just used EJB1.0 because JavaEE6 made it simple, lightweight,etc. – Sree Rama Apr 10 '13 at 05:45
  • The only problem with Spring for me is my team is completely new to Spring, but I may need to choose spring or traditional MVC with dao,value objects,servlets,etc. Because I want sql queries with multiple joins for populate and insert records should work. – Sree Rama Apr 10 '13 at 05:50
  • maggu, thank your for the comments. – Sree Rama Apr 10 '13 at 05:51
0

No. Or re-design the application without using EJBs before migrating to Tomcat 7.

Sree Rama
  • 1,207
  • 12
  • 25
  • EJB3.1 may be light weight, but container dependent. We can deploy the application WAR file in other Java EE6 certified servers like JBOSS, Weblogic, WebSphere. – Sree Rama Apr 16 '13 at 20:25
0

tomcat is web container, may be tomcat 8 will support java ee 7, but you free to use Apache Tomee !!!

But in general when you use tomcat, use Spring, if you prefer Jboss or glassfish, use EJB3

Armen Arzumanyan
  • 1,939
  • 3
  • 30
  • 56