EJB3 Design Patterns (Session Beans)
I've been learning about EJB3 and JSF as a potential technology for a new web app. As part of my learning about EJB3 and JSF, I came across this tutorial on the NetBeans site:
http://www.netbeans.org/kb/55/ejb30.html
In the tutorial there is one entity class, NewsEntity, from which a session bean is created, NewsEntityFacade and the interface NewsEntityFacadeLocal. It seems a little weird to me that the interface is called NewsEntityFacadeLocal and the implementing class called NewsEntityFacade. I would think that the interface should be called NewsEntityFacade and the implementing class NewsEntityFacadeLocal.
Question 1: Can anyone explain why the names are backwards (at least to my thinking)?
Also, I've been trying to find some best practices on EJB3 design patterns, but haven't come up with much. I did find some at https://blueprints.dev.java.net/bpcatalog/ee5/persistence/ejbfacade.html. Based on this pattern and the NetBeans tutorial, I think I've come across two different patterns, but since most of the examples are very simple, it's hard to tell.
Question 2: Are these two distinct patterns?
1. Session facade/entity (NB example)
2. Session facade which groups business logic and may reference multiple entity beans.
Question 3: If I have identified two patterns, can anyone tell me what they consider the pros/cons of either/both?
Thanks in advance!
The SRDemo available as an automatic update in JDeveloper 10.1.3.0.4 shows an application using local EJB 3.0 session beans. To access them in the web application you will need an entry in the web.xml like:
<ejb-local-ref>
<ejb-ref-name>ejb/local/SRPublicFacade</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>oracle.srdemo.model.SRPublicFacade</local>
<ejb-link>SRPublicFacade</ejb-link>
</ejb-local-ref>To lookup the session bean within you presentation you need to do a JNDI lookup. In my example I have:
new InitialContext().lookup("java:comp/env/ejb/local/SRPublicFacade");Doug
Similar Messages
-
Business delegate and Session facade design patterns
Does any one tell me, what is the difference between business delegate and session facade design patterns.
1. Session Facade decouples client code from Entity beans introducing session bean as a middle layer while Business Delegate decouples client code from EJB layer ( Session beans).
2. SF reduces network overhead while BD reduces maintenance overhead.
3. In SF any change in Session bean would make client code change.
While in DB client is totally separate from Session bean because BD layer insulate client from Session beans(EJB layer).
3. In only SF scenario, Client coder has to know about EJB programming but BD pattern no EJB specialization needed.
4.SF emphasizes on separation of Verb, Noun scenario while BD emphasizes on separation of client(presentable) and EJB layer.
Anybody pls suggest more differences ? -
JavaBean Models, Command Bean and J2EE Design Pattern
Hello,
I have read the available "How To", Using EJBs in Web Dynpro Applications where the author mentions that one should use a Command Bean (according to J2EE Design Patterns) so that one can invoke business methods in a Session Bean from our Web Dynpro Application. Well, although, I have read some available articles in the internet about J2EE design patterns, I still have some questions about command beans and its usage in Web Dynpro applications.
I have developed a WD App which uses EJBs to read data from the DB.
Let's suppose I only have two tables: BOOKS and AUTHORS.
Lets also suppose I have to Entity Beans (one for each table) and a Session Bean with two methods: Book[] getAllBooks() and Author[] getAllAuthors();
I also have a Command Bean which I imported in my WD App.
My questions are:
How should I design my Command Bean?
Can I have only one Command Bean with two methods each calling one of the methods of the Session Bean?
Or instead should I design two Command Beans, one for each call?
In the last case do the methods must be named <b>execute</b> or can I name them whatever I want?
Furthermore, how should I store the data in my command bean? In instance variables?
If so, can I use array of a class representing a record in the database table (for instance, classes Book and Author) or do I have to store the data in a generic collection (such as ArrayList for instance)?
I ask this last question because if I try to store the data in an array when I am importing the Command Bean as a JavaBean model I always get an error.
One last question: Can the Command Bean execute method directly return the data or should I always store the data in an instance variable an then get it using getter methods?
I know this questions are more about J2EE Design Patterns and JavaBeans specification than they are about Web Dynpro but I also have doubts about the rules that the command bean must obey in order to accomplish a successful JavaBean model import in WD.
Some guidance or tips would be highly appreciated.
King RegardsI have the same problem.
Does anyone know the solution?
Thanks
Davide -
Transaction Problem in Session Facade Design Pattern
Hi
Well Sorry for giving wrang title to the topic, coz of which I have not received and reply.
I am using session facade design pattern.
I have Action class calling session facade method "getData" . This method calls "findByPrimaryKey" method in BMP.
Method "getData" has transaction attribute as "RequiresNew" and "findByPrimaryKey" has "Required".
This combination does not assign identity to BMP hence I can not use setter getter method for retriving data(throws nullpointer exception when getter method accessed) I have made sure that I am accessing table and getting data in to BMP but as BMP is not ablle to hoild any identity its not allowing me to use BMP's getter method in session facade.
I have Used Same transaction attribute for create method called by "addNew" method of session facade bean.
Transaction method for "addNew" is "RequiresNew" and for "create" is "Required".
It works fine and gives identity toBMP hense I can use Setter getter method defined in BMP bean.
How can I avoid this and get BMP an identity?
Thanking in Advance,
Chintan.Sorry, how is this related to JSF?
There's an OO/patterns forum out. Consider reposting the question over there with formatted code. -
Difference between Session Facade and Business Delegate design patterns
Can someone tell me the differences between Session Facade and Business Delegate design patterns
1. Session Facade decouples client code from Entity beans introducing session bean as a middle layer while Business Delegate decouples client code from EJB layer ( Session beans).
2. SF reduces network overhead while BD reduces maintenance overhead.
3. In SF any change in Session bean would make client code change.
While in DB client is totally separate from Session bean because BD layer insulate client from Session beans(EJB layer).
3. In only SF scenario, Client coder has to know about EJB programming but BD pattern no EJB specialization needed.
4.SF emphasizes on separation of Verb, Noun scenario while BD emphasizes on separation of client(presentable) and EJB layer.
Anybody pls suggest more differences ? -
How can i design a EJB application using session Beans?
Hello,
I am designing a Find application using EJB. Here a user is prompted a search page, where he can enter the search criteria's. Then on click of submit, the query is formed at the server side depending on what criteria's were selected. Then a jdbc query is performed and the results are returned back to the user. Here no session is maintained for the users. Can anyone suggest me how to design this application using EJB. Should i use entity beans for this or session beans will suffice? Should the jdbc query be performed in the bean itself or should it be outside in a helper class? Please kindlu suggest me the design for this application...
Regards,
SubbuHi,
First of all, I'm unable to figure out why you need to use EJB for this scenario. You can write a helper class to frame and execute the query.
If you really want to use EJB, then I suggest you use a stateless Session Bean with transaction attribute as TX_NOT_SUPPORTED. From the session bean, you can call the helper class. But, by avoiding the session bean, you can eliminate remote calls, thus improving your performance. Also, check if the database & the db driver you are using supports sql caching.
Regards,
Raj. -
JDeveloper EJB3 Session Bean Problem
Hi Everyone,
I am new to JDeveloper. I tried to do a EJB3 Stateless Session Bean. I want to add the AroundInvoke Function to the Bean class. At below
@AroundInvoke
// mark this method as a bean interceptor
public Object checkPermission(InvocationContext ic) throws Exception {
System.out.println("*** checkPermission interceptor invoked");
// you can implement your own security framework using interceptors
if (!ic.getEJBContext().getCallerPrincipal().getName().equals("oc4jadmin")) {
throw new SecurityException("Caller: '"
+ ic.getEJBContext().getCallerPrincipal().getName()
+ "' does not have permissions for method "
+ ic.getMethod());
return ic.proceed();
However, the Jdeveloper 11g keep show me the error message that AroundInvoke is not found. Then I put the import javax.ejb.AroundInvoke. It still complain import javax.ejb.AroundInoke not found.
Please help and advise.
Thank youA small tip - if you go to the add a library dialog in the project properties you'll see a search box at the top - you can put a class name there and JDeveloper will show you in which library it is.
-
Hello, I have following problem with the ejb3 and session bean lookup:
For example, I have a session bean with some dummy method, i.e. getInfo() :
@Stateless
public class MySessionBean implements MySessionLocal {
public String getInfo() {return "Hello from Session bean";}
When I lookup and use this bean in servlet in the following way, everything is OK:
public class MyServlet extends HttpServlet {
@EJB() MySessionLocal mySession;
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
out.println(mySession.getInfo());
On the other side, when I create some java bean object as a facade, import and use it in servlet , it doesn't work:
public class Facade {
@EJB() MySessionLocal mySession;
public String getInfo() { return mySession.getInfo();}
public class MyServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
Facade myFacade = new Facade();
out.println(myFacade.getInfo());
When servlet runs and gets to the command myFacade.getInfo(), NullPointerException is thrown, because mySession object in myFacade is null (ejb lookup method probably fails to perform...)
I'm trying to use Facade to be able to use my Session Bean in JSP pages, i.e. to do something like <jsp:useBean id="myFacade" class="Facade" ...>
Could someone clarify why lookup doesn't work in javabean object, despite the fact that it works in servlets?
P.S. I'm running the latest promoted build (b31) of GlassFish (maybe this is the cause) and NetBeans IDE...Hi,
Please try this ... http://weblogic-wonders.com/weblogic/2009/08/16/weblogic-10-3-ejb3-local-lookup-sample/ (Lookup from JSP)
and
http://weblogic-wonders.com/weblogic/2009/08/15/hello-world-2/ (Lookup/Injection from Servlet)
Thanks
Jay SenSharma -
What is meant by session Facade design pattern
please give me
cripes
http://www.google.com/search?q=what+is+meant+by+session+Facade+design+pattern
Who'd have thought it? ;-)
kind regards,
Jos -
Flex + Glassfish EJB3 stateless session bean
Hi, I'm new to Flex. We´re in the process of adopting a
front end web technology. In the Server side we have a JavaEE
Application with several EJB3 session beans deployed in Glassfish
V2ur1. I just wonder if someone could lead me to a sample flex
application that access stateless EJB3 session beans that return
Entity Beans. Which is the best approach? Could anybody share some
sample code with me? Thanks a lot.
My mail is [email protected]Hi,
1) First of all you'll need to download and deploy LiveCycle
Data Services or BlazeDS on your application server.
2) Then download the Flex EJB factory from Adobe Exchange (
http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&extid=1089970)
and add it to your Data Services.
3) Declare your session beans as destinations in
remoting-config.xml
I remember having trouble to get it working on Glassfish so
for Flex/EJB3 development I switched to JBoss. Maybe newer versions
of Glassfish and Data Services will work together more easily.
After setting up the server-side part you invoke session
beans just like any other RemoteObjects (see Flex docs).
Good luck :) -
Problem Deploying EJB3 Stateless session bean in Jboss4.0.3
Hi All,
I have developed an EJB 3 Stateless session bean and tried to deploy in JBoss 4.0.3 , But i get the following Exception.
javax.naming.NameNotFoundException: ejb not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
at org.jnp.server.NamingServer.lookup(NamingServer.java:249)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at org.apache.jsp.session_jsp._jspService(org.apache.jsp.session_jsp:69)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:157)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)
I am sorry if the question is silly..... My Remote Interface will be one like this
import javax.ejb.Remote;
@Remote
public interface CityService {
public String getCity();
And My Bean Class will be
import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
@EJB
@Remote(CityService.class)
@Stateless(mappedName="ejb/CityService")
public class CityServiceBean implements CityService {
public String getCity(){
return "Chennai Metropolitan";
And the client which invokes the bean will be
InitialContext ctx = new InitialContext();
CityService c = (CityService)ctx.lookup("ejb/CityService");
System.out.println("Msg from Bean"+c.getCity());
please help me out of this issue....
Thanks in advanceford wrote:
If you deploy your application in a .ear, you also can use this:
You have to set a name to your EJBBean -> @Stateless(name = "XXX")
The client for remote interface -> cxt.lookup(Name_of_your_own_ear_without_extension + "/XXX/Remote");
The client for local interface -> cxt.lookup(Name_of_your_own_ear_without_extension + "/XXX/Local");the problem with this approach is that if you version your ears, the version numbers show up in the jndi names, and your client code will be hard coded to specific server versions. -
Reg. Issue with Session Bean -- EJB3
Have a state full session bean (SFSB):
@Stateful
public class test implements itest{
private static final long serialVersionUID = -4929837299158287545L;
private int q= 0;
public void assign(int p) {
q = p;
Inetrface is:.
@Remote
public interface itest extends Serializable {
public void assign(int p);
Accessed as:
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
properties.put(Context.PROVIDER_URL, "localhost");
InitialContext ctx = new InitialContext(properties);
Object i = (itest) ctx.lookup("test/remote");
itest t = (itest) PortableRemoteObject.narrow(i, itest.class);
This piece of code fails giving error
java.lang.ClassCastException: $Proxy135 ....
But if i change, the state full session bean (SFSB) to stateless session bean (SLSB) i.e @Stateless
Everything works fine.
Environment : JBoss as the App Server.
Any help appreciated.Hi Shailesh,
Thank you for the reply.
I checked the JCO's and everything is working fine.
And to be more clear.
I have the same application in 2 roles and in ESS role the application is working fine but the user in discussion is an external user and we have config in place for externals.
In XYZ role where the application is not working we created a new role to satisfy the authorizations. which are same in dev and QA. the application for the user with same authorization is working fine in dev but the same is not working in QA.
Any other inputs will be helpful.
Thanks & Regards,
Pramod -
General Design With Database and Session Bean Question
I have an application I am developing where users connect to individual databases located on a server. When they login an admin table is accessed which shows what databases they have permissions to. I am then storing the connection to the database in a backing bean. Hoping to use this connection throughout the session. Is this a good practice to have a users connection left open over the session? I can't create a database pool for each individual database and each user for that database.
If I can store that database connection in a session bean. How do I access that connection from another bean. Or from another java class? I am using Glassfish for my application server with JSF1.2. I have looked at resource injection but have not had any luck with sharing the session bean information.
Sorry if this is a trivial question. I have been a Java developer for years. But just starting developing webapps using JSF.
ThanksJuCobb2 wrote:
I am then storing the connection to the database in a backing bean. Hoping to use this connection throughout the session. Is this a good practice to have a users connection left open over the session? No it is not. Why should you do so? Always keep the lifetime of connection, statement and resultset as short as possible. -
Can a session bean call a database?? design issue
Is there a thumb rule that all my database calls should be made through an
entity bean ?
I have data that needs to be saved across calls as well as persisted to the
database. But the instance of the object is not going to be modified
concurrently. So basically there is no problem of maintaining the
consistency of data. The class itself takes care of it. Can I put all this
in a STATEFUL session bean which calls my database ??
Devu.http://java.sun.com/j2ee/sdk_1.2.1/techdocs/guides/ejb/html/Overview4.html#9382
devu wrote:
Is there a thumb rule that all my database calls should be made through an
entity bean ?
I have data that needs to be saved across calls as well as persisted to the
database. But the instance of the object is not going to be modified
concurrently. So basically there is no problem of maintaining the
consistency of data. The class itself takes care of it. Can I put all this
in a STATEFUL session bean which calls my database ??
Devu. -
Hi,I have a problem about @EJB in session bean.
There are 2 session beans, SessionBeanA & SessionBeanB
in SessionBeanA:
@EJB(beanName="SessionBeanB")
SessionBeanBInterface sessionBeanB;
in SessionBeanB:
@EJB(beanName="SessionBeanA")
SessionBeanAInterface sessionBeanA;
when deploy the ejb, jboss will consider that SessionBeanA depends on SessionBeanA , and SessionBeanA depends on SessionBeanB, so jboss will output that:
--- MBeans waiting for other MBeans ---
What's the problem?How to solve it?
Thanks.If they're both stateful session beans, it is an application error, since in that case injection has the side effect of creating a new stateful session bean identity. Allowing that would result in an infinite loop.
If at least one is a stateless session bean, there's nothing wrong with the code. EJB references are always proxies. There is no notion of initialization ordering dependencies between such beans if they're packaged in the same application. In this case the JBoss container would be restricting something that is allowed by the EJB specification so it's a JBoss bug.
Maybe you are looking for
-
Material group is not updated in EINA
Hi Experts, We are having a situation for EINA table. Whenever a PIR is created with reference to material, its material group is copied from table MARA to PIR, but it is not being updated in EINA table. Where as if PIR is created with refernce to ma
-
How to submit a Feature Request
Anyone know how ot submit a feature request to the Mail team? I'm so tired of inline attachments. I feel like I'm using a mail client from the mid 90's.
-
i have a blackberry 9300 curve and i wondered how i can remove email adresses from my contacts list as i want to just be able to see numbers and facebook contacts?
-
Why archivelog mode is mandatory for hot backups.
Hi, Why the database should be put in archivelog mode when we take hot backups. What happens actually. Why can't we put in noarchivelog mode and take hot backups?
-
Numbers on iMac under Maverick. For each sheet in a spreadsheet (Numbers file) I have provided a corresponding sheet (to replace it). In the new sheet I want to insert a formula referencing the corresponding cell in the original sheet. I want to be a