EJB vs Spring

Hi All,
I got one doubt regarding EJB vs Spring!
Is Spring completely replacement to EJB's?
Which technology is suitable to develope the distributed applications?
Thanks in advance,
Krishna

Spring more or less complements EJB.

Similar Messages

  • EJB calling Spring Bean with non XA Datasources causing Rollback Exception

    We have an EJB CMT with Required calling a spring bean (@Transactional Propagation.NOT_SUPPORTED). This is causing an Rollback Exception saying 2 phase commit must be enabled. The EJB has to write to datasource 1, but the Spring Bean is ready only on Data Source 2. The Data Sources are set to use Non XA Driver with Support Global Transaction enabled for One phase commit. Any help is appreciated.

    We have an EJB CMT with Required calling a spring bean (@Transactional Propagation.NOT_SUPPORTED). This is causing an Rollback Exception saying 2 phase commit must be enabled. The EJB has to write to datasource 1, but the Spring Bean is ready only on Data Source 2. The Data Sources are set to use Non XA Driver with Support Global Transaction enabled for One phase commit. Any help is appreciated.

  • Anyone have experience using EJB with spring?

    I'm getting this totally useless stack trace trying to test a simple query through EJB:
    WARNING: JBO-29000: Error injecting reference; nested exception is: java.lang.InstantiationException: Error injecting reference
    oracle.jbo.JboException: JBO-29000: Error injecting reference; nested exception is: java.lang.InstantiationException: Error injecting reference
    Then I made my own LifeCycle class to get a better stack trace. It was better, but it didn't help much...:
    ## Detail 0 ##
    javax.ejb.EJBException: Error injecting reference; nested exception is: java.lang.InstantiationException: Error injecting reference
    java.lang.InstantiationException: Error injecting reference
         at com.evermind.server.DependencyManager.resolveDependencies(DependencyManager.java:157)
         at com.evermind.server.ejb.LifecycleManager.postConstruct(LifecycleManager.java:98)
         at com.evermind.server.ejb.StatelessSessionBeanPool.createContextImpl(StatelessSessionBeanPool.java:40)
         at com.evermind.server.ejb.BeanPool.createContext(BeanPool.java:418)
         at com.evermind.server.ejb.BeanPool.allocateContext(BeanPool.java:244)
         at com.evermind.server.ejb.StatelessSessionEJBHome.getContextInstance(StatelessSessionEJBHome.java:25)
         at com.evermind.server.ejb.StatelessSessionEJBObject.OC4J_invokeMethod(StatelessSessionEJBObject.java:86)
         at CmMetaServiceEJB_LocalProxy_4j6m9m9.queryMetaObjectFindAll(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at oracle.adf.model.binding.DCInvokeMethod.invokeMethod(DCInvokeMethod.java:507)
         at oracle.adf.model.binding.DCDataControl.invokeMethod(DCDataControl.java:1795)
         at oracle.adf.model.generic.DCGenericDataControl.invokeMethod(DCGenericDataControl.java:248)
         at oracle.adf.model.binding.DCInvokeMethod.callMethod(DCInvokeMethod.java:219)
         at oracle.jbo.uicli.binding.JUCtrlActionBinding.doIt(JUCtrlActionBinding.java:1289)
         at oracle.adf.model.binding.DCDataControl.invokeOperation(DCDataControl.java:1802)
         at oracle.adf.model.generic.DCGenericDataControl.invokeOperation(DCGenericDataControl.java:266)
         at oracle.adf.model.adapter.AdapterDCService.invokeOperation(AdapterDCService.java:305)
         at oracle.jbo.uicli.binding.JUCtrlActionBinding.invoke(JUCtrlActionBinding.java:627)
         at oracle.jbo.uicli.binding.JUMethodIteratorDef$JUMethodIteratorBinding.invokeMethodAction(JUMethodIteratorDef.java:160)
         at oracle.jbo.uicli.binding.JUMethodIteratorDef$JUMethodIteratorBinding.initSourceRSI(JUMethodIteratorDef.java:542)
         at oracle.adf.model.binding.DCIteratorBinding.callInitSourceRSI(DCIteratorBinding.java:1436)
         at oracle.adf.model.binding.DCIteratorBinding.getRowSetIterator(DCIteratorBinding.java:1420)
         at oracle.adf.model.binding.DCIteratorBinding.setRangeSize(DCIteratorBinding.java:2703)
         at oracle.adf.model.binding.DCBindingContainer.internalRefreshControl(DCBindingContainer.java:2487)
         at oracle.adf.model.binding.DCBindingContainer.refresh(DCBindingContainer.java:2260)
         at oracle.adf.controller.v2.lifecycle.PageLifecycleImpl.prepareModel(PageLifecycleImpl.java:99)
         at oracle.adf.controller.faces.lifecycle.FacesPageLifecycle.prepareModel(FacesPageLifecycle.java:72)
         at oracle.adf.controller.v2.lifecycle.Lifecycle$8.execute(Lifecycle.java:210)
         at oracle.adf.controller.v2.lifecycle.Lifecycle.executePhase(Lifecycle.java:116)
         at oracle.adf.controller.faces.lifecycle.ADFPhaseListener.mav$executePhase(ADFPhaseListener.java:29)
         at oracle.adf.controller.faces.lifecycle.ADFPhaseListener$4.after(ADFPhaseListener.java:327)
         at oracle.adf.controller.faces.lifecycle.ADFPhaseListener.afterPhase(ADFPhaseListener.java:90)
         at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:254)
         at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:110)
         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:213)
         at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
         at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._invokeDoFilter(AdfFacesFilterImpl.java:228)
         at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._doFilterImpl(AdfFacesFilterImpl.java:197)
         at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl.doFilter(AdfFacesFilterImpl.java:123)
         at oracle.adf.view.faces.webapp.AdfFacesFilter.doFilter(AdfFacesFilter.java:103)
         at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)
         at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:162)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:621)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
         at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
         at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:122)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:111)
         at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
         at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:239)
         at oracle.oc4j.network.ServerSocketAcceptHandler.access$700(ServerSocketAcceptHandler.java:34)
         at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:880)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:298)
         at java.lang.Thread.run(Thread.java:595)
    Caused by: java.lang.IllegalArgumentException
         at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)
         at java.lang.reflect.Field.set(Field.java:656)
         at com.evermind.server.deployment.InjectionField.inject(InjectionField.java:46)
         at com.evermind.server.DependencyManager.resolveDependencies(DependencyManager.java:154)
         ... 57 more
    does anyone know how I can get a better stack trace with reference to my own files?

    Please refer
    http://www.oracle.com/technology/tech/java/oc4j/1013/how_to/how-to-ejb30-jpa-spring/doc/how-to-ejb30-jpa-spring.html

  • Custom Policy Step calling EJB

    Hi there,
    I'm a newby to OC4J and need some help in regards to some library issues. I've created an EJB using spring and deployed it to the oc4j container. Then I created an owsm custom policy step which retrieves the EJB bean using spring and retrieves the custom security header, which I then add to the current SOAP header. I wasn't quite sure how to create the custom policy step jar as it contains my spring jar as well as my ejb jar, so I used maven to create the jar with all my dependent jars as well. Everything works great, as in, it retrieves the EJB calls the method on the EJB which will retrieve a value from LDAP and then uses that value to query our data store and then return the object, but when it returns the object it throws the following exception:
    java.lang.LinkageError: Class com/cochlear/erpsecurity/domain/ErpSoapHeader violates loader constraints
    Which is due to the fact that I have the ErpSoapHeader in my custom policy step jar as well as my ejb jar. When I don't include the ejb jar in my custom policy step jar however then it give a class not found exception when trying to load the ejb with spring. Then I tried something dodgy and added the ejb jar to my server.xml in oracle.wsm.gateway shared library, but this caused the linkage error as well.
    Any help on how I can resolve this library issue will be great appreciated.
    Thanks so much,
    Ida

    Here's an example on how to add a custom SOAP header to the request message inside a custom step.
    public IResult execute(IMessageContext messageContext) throws Fault {
    MessageContext msgCtxt = (MessageContext) messageContext;
    SOAPEnvelope senv = msgCtxt.getRequest().getAxisMessage().getSOAPEnvelope();
    ((org.apache.axis.message.SOAPEnvelope)senv).setDirty(true);
    Name header = factory.createName("CustomHeader", "http://foo.com/custom/header");
    SOAPHeaderElement headerElement = senv.getHeader().addHeaderElement(header);
    headerElement.addTextNode("My custom header data");
    OWSM uses AXIS implementation internally to represent the SOAP message.
    Cheers,
    Vikas Jain

  • Problems while performing lookup for Local EJBs

    Can anybody tell me how can i perform local ejb lookup in Sun app Server 8.0/8.1 ?
    I have following entries in ejb-jar.xml.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar >
    <enterprise-beans>
    <session >
    <ejb-name>TeamLeaderBean</ejb-name>
    <local-home>spring.ejb.example.TeamLeaderLocalHome
    </local- home>
    <local>spring.ejb.example.TeamLeaderLocal</local>
    <ejb-class>spring.ejb.example.TeamLeaderBean</ejb-class>
    <session-type>Stateless</session-type>
    <transaction-type>Container</transaction-type>
    </session>
    </enterprise-beans>
    <assembly-descriptor></assembly-descriptor>
    </ejb-jar>
    In sun-ejb-jar.xml I have
    <sun-ejb-jar>
    <enterprise-beans>
    <ejb>
    <ejb-name>TeamLeaderBean</ejb-name>
    <jndi-name>TeamLeaderBeanLocal</jndi-name>
    </ejb>
    </enterprise-beans>
    </sun-ejb-jar>
    In the client EJBs code I have used following ways of performing lookup...
    ctx.lookup("java:comp/env//TeamLeaderBeanLocal");
    ctx.lookup("java:comp/env/ejb/local/TeamLeaderBeanLocal");
    ctx.lookup("ejb/TeamLeaderBeanLocal");
    Unfortunately none of these performs a successful lookup...???
    Can anybody solve my problem?

    In order to look up a local EJB from an EJB client you have to add an <ejb-local-ref> element for client EJB. So:
    <session>
    <ejb-name>MyClientEJB</ejb-name>
    <ejb-local-ref>
    <ejb-ref-name>ejb/TeamLeaderBeanLocal</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <ejb-link>TeamLeaderBeanLocal</ejb-link>
    </ejb-local-ref>
    </session>
    fil
    Can anybody tell me how can i perform local ejb
    lookup in Sun app Server 8.0/8.1 ?
    I have following entries in ejb-jar.xml.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems,
    Inc.//DTD Enterprise JavaBeans 2.0//EN"
    "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar >
    <enterprise-beans>
    <session >
    <ejb-name>TeamLeaderBean</ejb-name>
    <local-home>spring.ejb.example.TeamLeaderLocalHome
    </local- home>
    <local>spring.ejb.example.TeamLeaderLocal</local>
    <ejb-class>spring.ejb.example.TeamLeaderBean</ejb-clas
    s>
    <session-type>Stateless</session-type>
    <transaction-type>Container</transaction-type>
    </session>
    </enterprise-beans>
    <assembly-descriptor></assembly-descriptor>
    </ejb-jar>
    In sun-ejb-jar.xml I have
    <sun-ejb-jar>
    <enterprise-beans>
    <ejb>
    <ejb-name>TeamLeaderBean</ejb-name>
    <jndi-name>TeamLeaderBeanLocal</jndi-name>
    </ejb>
    </enterprise-beans>
    </sun-ejb-jar>
    In the client EJBs code I have used following ways of
    performing lookup...
    ctx.lookup("java:comp/env//TeamLeaderBeanLocal");
    ctx.lookup("java:comp/env/ejb/local/TeamLeaderBeanLoca
    l");
    ctx.lookup("ejb/TeamLeaderBeanLocal");
    Unfortunately none of these performs a successful
    lookup...???
    Can anybody solve my problem?

  • Do we need ejb for persistance of obects

    hai ,
    I heard that hibernate can be used for persiatance of object .
    Which method is more efficient.
    regards

    Hi,
    Entity beans provide a lot of services for ex.
    1. Authentication & Authorization
    2. TX Management
    3. Resource management.
    4. Lifecycle managment by container
    5. Distributed computing environment etc. to name a few.
    There are advantages of using EJB as well as some disadvantages. However use of a particular technology such as EJB or Spring should be very carefully decided based purely on business needs.
    HTH
    VJ

  • My view on EJBs

    http://www.greengiraffesolutions.blogspot.com/

    Elaborate reply: I agree that EJBs are unnecessarily condemned for various reasons which you have cited. They are, in fact, pretty good in a fair number of situations which require a robust and scalable architecture. However, your view on Spring equivalence -
    I can't see a better alternative to J2EE/EJB. People say use Hibernate. The persistence machanism is simpler than EJBs. Fine, but what are you going to use for transactions, security, scalability and directory service (ie. JNDI)? You could cobble together something in Spring and then use "bits" of J2EE like JTA and JMS. But that sounds much messier and harder to maintain than using J2EE/EJB outright.
    is very premature because you don't seem to have researched the other part. The statement is pretty biased. I do agree that I found EJBs simpler than Hibernate but that may be because my EJB book has a good explanation of all the concepts. shrug Well, I recently found a well-written book on Hibernate and the author is a regular on the forum. The book has some good reviews. Let's see if that gives me a better idea of Hibernate and how it could be an alternative to persistence (and also how simple / complex it is).
    Spring as a framework has a neat (not cobbled up) and pretty flexible and it does not attempt to eliminate the place of EJBs. I use EJBs with Spring in my present project and all I could say is that Spring has a good architecture in itself. It saves me the time of writing the framework components and truly reuse other technologies (including EJBs, web services, ...).
    And finally, was the intent of the article to target the millions of developers who could not handle complexity rather than the technology itself? ;)
    I would partially agree that EJB has been mostly discarded because most developers like to get away from complexities and they find EJB complex. Some do find it simple. The future EJB specifications are aiming at reducing complexity and improving the efficiency [I can't comment much because I haven't been into EJB 3 specifications yet].

  • Beginning with EJB

    Hello,
    I'm a beginner in EJB, could you explain me their advantages vs spring
    thank you

    tamssaman wrote:
    Hello,
    I'm a beginner in EJB, could you explain me their advantages vs spring
    thank youOr disadvantages.
    It's a rather large topic, and I don't know how much you know about either EJBs or Spring.
    Spring doesn't require EJBs at all, which can be a major simplification. A Spring-based Java EE app can be deployed on a servlet/JSP engine rather than a full-blown Java EE app server, which can represent a substantial savings in license fees.
    Spring has several features (e.g., IoC, AOP, etc.) that go well beyond the EJB spec. The framework has lots of libraries that can help with development, too.
    %

  • Javafx 2.0 and ejb 3.x

    Hi,
    Does javafx 2.0 supports ejb injection. I am trying to inject ejb using annotation in fxController. It is simply not recognizing class ejb. Is it supposed to be done in old fashioned way using Service Locator.
    Could someone direct me to the literature related with javafx 2.0 and ejb.
    Thanks
    Sarad

    Hi Sarad,
    Injecting stuff (whether it is via EJB or Spring or whatever) usually requires that the bean is loaded (i.e. newed) via some context. In FXML the Controller is created via the FXMLLoader so unfortunately you can't easily inject into it. This is a bit of a problem for a few of us and there is an open feature request being considered for future releases: http://javafx-jira.kenai.com/browse/RT-16724. You may want to up-vote if this is important for you.
    At this stage of the game I would suggest your best bet is to have your controller look up your EJB via JNDI (as per the unit test in http://openejb.apache.org/3.0/injection-of-other-ejbs-example.html) and then have your controller delegate calls onto the EJB. You will likely want to thread the calls onto this as well, using JFX's Task or Service.
    Hope that helps,
    zonski
    Did you find this answer useful? If so, please mark as 'Correct' or 'Helpful'.

  • Spring

    Hello!
    I have a jboss server and some web application using ejb, i was told to create a new webapp that would work separatley and use another database and to access my existing app from new one i need to use Spring, does anyone know a good tutorial or example how to do that?
    Thanx

    And their site has also specific pointers on how to access EJBs from Spring:
    http://www.springframework.org/docs/reference/ejb.html

  • Using Flex 2 with/without FDS

    I am presently designing a web architecture for a client, and
    ideally I would like to employ a Flex2 UI on a Tomcat/Java web
    server/server component framework (possibly Spring). I am trying to
    get a good handle on the necessity of Flex Data Services (FDS) in
    this architecture.
    What am I really losing should I choose *not* to employ FDS,
    and is rolling the entire server side with standard Java technology
    fairly doable? Does anyone have any first-hand experience doing
    this which they could share?
    Given an expert-level server-side Java experience level, I
    need to determine whether employing FDS is a necessity or not.
    Thanks,
    Brad

    quote:
    Originally posted by:
    holmes_z06
    only if you want to pay the licensing costs.
    We don't use FDS on our project, we just export XML. Might
    start using some SOAP in the future. There's no way we could
    justify the cost of FDS.
    -Jason
    Jason,
    Thanks for the reply. How have you found the effort required
    to manage the XML transmitted by the Flex 2 app to the server-side?
    Has this effort been minimal, or have you found this minor? For the
    most part, unless I can identify something major that FDS provides
    to an org already versed in doing enterprise-class (J2EE) server
    development, I'm not quite seeing the need for FDS. I understand
    the description of FDS, and the synching / JMS capabilities, but
    I'm not sure that this can't be fairly easily managed with standard
    Java server objects (servlets, EJBs, or Spring POJOs). I don't want
    to get into discussing licensing, but there needs to be
    justification for such, especially at a per CPU rate, which is a
    common need for everyone.
    I'd love to hear from anyone who has employed FDS, or is
    familiar with an org who has, who can speak specifically to the
    value add experienced through use of this product.
    Brad

  • Constructor calls in BlazeDS?

    I have a Java POJO that accesses a database. It establishes a connection to the database in the constructor, the uses that connection in each call to query the database.
    However, the query time is VERY slow, PAINFULLY slow. I suspect that the constructor is being called each time the query method is called.
    I am new to BlazeDS, so i am curious about a few things:
    1- is the constructor called each time i make a call to the remote object?
    2-is it possible to instantiate the object and keep it in memory so i can make references to the instantiated object instead?
    3-Would this be facilitated using EJB or Spring Framework? I am looking into these, but don't know enough yet to make the call myself.
    ANY information you can provide is GREATLY appreciated....

    sorry, i REALLY need this answered, if possible, so i'm going to BUMP it just this once!

  • Annotation  processed at run time in java Library?

    Could any one give me a example in java library where annotation is processed at run time? I know there are lot of example in EJB and spring but looking for some in jave core library?

    JavaFunda wrote:
    Could any one give me a example in java library where annotation is processed at run time? I know there are lot of example in EJB and spring but looking for some in jave core library?The mechanism would be the same regardless of where it is used.

  • How can i increase performance JSP with database?

    Hi,
    I am working a forum.
    I have been facing a problem.
    i am getting collection of records from sql server database to jsp page. here all the records to take long time (*delayness jsp with database*).
    plz any bodies know that increase the permance, tell me.
    thanks & regards,
    k.s.kumar

    again very bad idea never use Put DB Code or Business Logic or Special Service requests inside the servlets/backing beans.
    Ideally the below is the method which is recommended for a Peformant J2EE application which focuses at modulality,configurablity,scalablity & performance.
    http://java.sun.com/blueprints/corej2eepatterns/Patterns/index.html
    Anyways,it might be a costly in terms of investment.Ideally i personally fell the below way/patterm could be comparable.
    <!-- View / Presentation Layer -->
    STEP 1 --> VIEW RENDERED(JSP renders view using a View Object/Objects)
    STEP 2 --> USER (Fills Forms accordingly and request for an action)
    <!-- Controller part -->
    STEP 3 --> Controller(Servlet+Backing Bean)
    STEP 3.1 ---> Mapps the request made into a View Object & Scopes it (Done by servlet )
    STEP 3.2 ---> validation of the data in the VO (and servlet is responsible to find appropriate Backing Bean to pass on the respective View Object)
    STEP 3.3 ----> Backing Bean takes help of a ServiceLocator Object(Singleton Object) and gets appropriate Business Object which takes care of all the appropriate business rule(Managed by Specific Containers)
    <!-- Service Locator takes help of specific Stubs to provide access to specific business Object -->
    <!-- MODEL PART -->
    STEP 3.4 ---->Backing bean passes on respective View Object to the Business Object and Business Object apply business rule on the data recievd from the Backing bean and sends appropriate DTO to DAO Object(Singleton Object)
    STEP 3.5 ----> DAO executes responsible DB query and returns a DTO/Collection of DTO to Business Object.
    STEP 3.6 ----> Business Object apply business rules on the data and then passes it back to backing bean.
    STEP 3.7 -----> Backing Bean receievs appropriate DTO/Collection of DTO sent by Business Object Update the View Object Accordingly.
    STEP 3.8 -----> Depending on the results return by Business Object the backing bean returns to reference appropriate JSP to forward/redirect.
    STEP 3.9 -----> Servlet identifies the reference returned and forward/redirects accordingly.
    STEP 4 ---> Repeat STEP 1
    NOTE: One can make use of any builtin frameworks(like struts,JSF,tapestry,Spring MVC,etc or your custom built framework in VC layers, EJB or Spring IoC or Custom Built Component Layer handling business objects and any ORM like hibernate,Oracle Toplink,Ibatis,JDO,JPA or specific custom devoloped DAO layer) to do this job.
    Might Sound bit complicated but is a better way to plug & play with each layer and can enusure other layer is not distrubed because of change in one layer,distributes the load on respective layer & so on.
    Hope that sounds logical
    REGARDS,
    RaHuL

  • 我眼中的J2EE

    周末写的一点体会:
    ejb是什么
    很长时间以来,我们一直被误导了,以为只有采用了ejb技术的系统才算真正玩了ejb。后来才明白J2EE的内涵要比ejb广的多,是一套使用Java进行企业级开发的技术规范,包含了大部分核心服务如JTA事务管理, 资源池,线程管理,还有jdbc,jsp,servlet等应用技术。而EJB仅仅是一个使用了JTA事务管理、线程管理等J2EE基础服务的分布式的组件标准。
    为什么需要ejb
    按照官方的说法:
    Enterprise JavaBeans will make it easy to write applications. Application developers will not have to understand low-level transaction and state management details; multithreading;resource pooling; and other complex low-level APIs.
    &#10065; Declarative transaction management
    &#10065; Remoting
    &#10065; Clustering
    &#10065; Thread management
    &#10065; Instance pooling
    &#10065; Resource management
    &#10065; Security
    &#10065; Management of business objects
    记得一个人写文章说:“EJB最大的诱人之处是她把应用程序和服务器分开了,我们再也不用和那些服务器上的复杂的资源打交道了,什么数据库,什么进程,线程,什么安全权限,什么套接字,都见鬼去吧,我们只需要专著于我们的商业逻辑的实现了。”
    ejb的许诺兑现了吗
    ejb已经出现5、6年时间了,很多J2EE项目才也采用了ejb,sun所描述的美好前景也并没有实现。
    1. Ejb规范本身是很复杂的,以至于没有多少开发人员去阅读他。Ejb总是与复杂联系在一起的,并没有减轻开发人员的负担。Ejb container像一个黑盒子,ejb在里面如何运行的,机制如何,很多人都说不出ejb container是如何处理异常的,跟事务有什么联系。
    Ejb的运行效率如何,瓶颈在什么地方,没有人知道。(在Oracle中的调优我们可以很精确的找出是程序甚至说哪条SQL语句的原因,Oracle配置的原因,操作系统和硬件的原因)。
    2. Ejb的复杂意味着程序的开发效率是低的,以致于Jbuilder提供了图形化的设计工具(一个包中的ejb只能由一个人来开发,否则合并比较麻烦) ,Xdoclet是另外一种辅助开发的方式。另外,拿entity bean来讲,每次想按照不同的参数进行查询,都要去为entity bean重新定义的一个select方法,然后编译发布,然后在业务逻辑中调用。
    3. Ejb是在容器中执行的,意味着我们不能像一般的javabean那样来对待他,与javabean像比,他是一个需要其他环境的重量级实现,单元测试是很困难的。
    4. 关于entity bean,Marc fluery的文章中说Cache is the king,可是数据库中已经有cache了,为什么还要去cache entity bean(相对于enity bean的复杂性,数据的传输开销还是很小的),仅仅是因为采用了entity bean而看起来更面向对象吗。
    Core j2ee patterns和一些所谓最佳实现的书都有相当一部分内容来正确和简化使用ejb的。
    相信Ejb 3.0在简化方面会做了不少工作。
    为entity bean寻找理由, 构件与对象
    一开始接触entity bean,感到的就是复杂,开发效率低,难以维护。
    一般来讲,使用entity bean都是完成数据持久的功能。
    后来看了hibernate,很简单,开始困惑,总以为entity bean之所以存在,还是有他存在的理由,于是列举了具备的安全,事务,分布式计算等方面的优点。
    后来还是开始怀疑entity bean存在的必要,因为那些功能与优点都可以通过session bean封装其他jdbc操作或者hibernate来实现,想来想去entity bean唯一的不同就是构件了,更像客观存在的domain model,而不是从数据库里面取出来的数据,entity bean使对象看起来更像真实的世界。
    构件之所以存在,是与分布式计算分不开的。在一个系统中,你可以通过另外一个系统来调用业务逻辑和数据访问,不同的系统通过构件来完美结合。
    (其实torque也不错,就是不能操作多个数据源,另外就是自己生成了相关java文件来实现or mapping的功能,而不是像hibernate那样通过xml文件来配置实现。)
    我们需要分布式吗,Distribution and Scalability
    分布式意味着在网络之间进行协调调用,意味着复杂,除非必要,就不要采用分布式技术。
    以前以为采用ejb,程序就是分布式的,就具备了可伸缩性。
    抛开可以按功能来划分访问的系统,其实可伸缩性就表明了是需要Cluster的(Cluster并不完全意味着分布式,只是很多分布式体系提供了Cluster功能),而Cluster中的难点就是如何同步复制不同App Server之间的数据,而App Server是与很多资源相连的,程序执行状态,Session变量、数据库连接状态,我们如何复制呢。(好不容易理解了Oracle RAC,而我觉得Oracle的同步的资源都是内部的)。
    重量级与轻量级(ejb container vs spring)
    在公司论坛上看到一个讨论heavyweight与lightweight的区别,如果说把一项技术的规范和文档拿出来秤,操过500克就是heavyweight,否则就是lightweight。
    似乎heavyweight总是与复杂性联系起来的。
    就如同ejb container与spring。
    我们所开发的系统并不是都是分布式的,也并不都是那么复杂的,才会有spring的出现。
    客观的说,ejb container能够提供的功能,spring基本上都能够以javabean的方式实现。
    区别还是前面说的ejb container是一个构件的容器,而spring是一个对象的容器,一个转移对象间的耦合,把业务逻辑与安全、事务等相分离的轻量级解决方案。
    Spring 最核心的部件就是它的Bean Container,在整个框架中扮演了一个软总线,它使框架内部的组件按照一定的耦合度组装起来,对外提供一个服务的接口
    如果开发一个需要跟多个系统交互运行的分布式系统还是使用ejb吧, spring取代不了ejb。
    对于大多数web应用,应该是一个不需要访问其他系统的多层系统(即使可能访问多个数据库),采用spring把。Spring+hibernate应该是一个比较好的组合,但和ejb container相比,spring的缺点就是没有规范。
    这么多年来,java总是在不停的修修补补中前进,
    一切都是对象吗, OO的困惑
    j2ee系统的开发应该都是采用面向对象技术,关键是怎么用的问题。
    很久以前,在重粒子空间的一篇文章里,把一切都描述为对象,整个世界是那样的优美。我也深信不疑。
    由于在我们的程序中,主要是针对数据处理和流程处理的,才知道用对象来表达不是那么自然。就查到了transaction script和domain model的概念。
    transaction script就是对表示层用户输入的处理程序。包括验证和计算,存储,调用其它系统的操作,把数据回传给表示层。
    domain model是所谓的域模型, 跟客观世界中的实体相对应。
      transaction script属于结构性思维,直观一些,在系统中如果domain model不是很明显,采用transaction script也是一个不错的选择。domain model属于oo思维,需要较强的抽象能力,习惯了就可以能够组织很复杂的逻辑,另外,我们必须考虑哪些行为是通用的、属于domain model的,哪些不是,可以通过一些xxxManager或者xxxController所实现的。
    举一个例子,假如查看今天A银行到B银行的所有转帐记录, 是列出A银行所有帐户对象来查看是否进行了转帐,还是从数据库中直接查询今天的转帐记录直观。Transaction script还是有他的用处的,可以说,所有的程序都要通过Transaction script来组织,程度不同而已。
    这个世界,除了对象,还是有对象间的关系、行为规则和记录(数据)的,观察的角度不同,就可以从不同的角度来组织系统,不一定需要用对象来表示。比如一个人是一个对象,档案所记录他一生的活动是什么,数据,是我们关注的一个方面,我们来查档案就够了,而不用去问这个人。
    不排斥DB
    在网上很多文章中,都会提到把系统想象成一个完美的oo世界,而是db只不过是一个持久化的手段而已。
    我一直认为db也是一个完整的世界,能够做很多事情,特别是在效率方案。
    所谓采用oo和j2ee的系统,模拟现实世界,注重对象间的行为和关系,比较适合oltp的应用。
    而db则是从数据角度来进行关注一个系统的,没有oo那么复杂的关系,处理效率很高,特别是在大批量数据处理和长事务处理的时候有自己的优势。在不存在明显错误的前提下,db的实现一般要比oo语言要高效,只是从大的方向来讲有它自己的处理范围。
    Oo和db需要一个适应、协作的过程。
    你有多少系统是需要从不同数据库之间移植的,必要的时候,在j2ee方案中采用些db技术还是不错的选择。
    MVC
    Spring,struts,webwork2
    Model
    C/s结构下,在pb程序中,一个datawindow几乎可以从界面交互、数据绑定以及访问数据库等一系列功能,你专心考虑业务实现就可以了。
    在多层结构的程序中,这种好日子一去不复返了,因为分层,属于接口性质的细节要靠你自己来实现,仅仅在数据方面,就出现了vo, dto,po,detached po,domain model等众多的名词。
    不同的层专注于不同的功能,对于界面展现,在struts中有actionform用于显示,业务层的数据用vo来表示,在网络传输中又用到了dto(特殊的vo),数据保存又用到了po了。
    在这种情况下,数据的完整性是一个很麻烦的问题,假如actionform可能和vo的数据不完全一致,不完全一致的内容在页面生成的时候就丢失了,要么把vo缓存起来在需要时进行更新,要么在业务层从新query数据到vo进行更新,如果业务层是单独的而且持久层是ejb还要再次进行查询更新。效率很低,而且容易出错。
    在hibernate中出现detached po,可以当成vo,po来用,也可以把数据传送到前台界面来使用,最后再传递回业务层进行业务操作和保存。由于detached po可以是带有业务逻辑的域对象,甚至可以在界面中调用detached po的逻辑。缺点就是如果detached po中存在lazy load的依赖对象,就不是那么好玩了,这种情况应该是可以根据编程时的具体情况来选择避免的。
    Domain model,是一个特殊的值对象,带有业务逻辑和持久功能。他接受和加工客户端数据,实现业务逻辑,并把数据进行保存。Domain model中数据完整性和持久问题还是要在内部处理,只是从分散的位置集中到一处了。
    总之,在多层结构中没有一种方案能够像pb中的datawindow一样智能和完美的数据处理方案。总是有很多东西要自己处理。
    另外,web页面是一个无状态的简单页面,界面上的只有通过javascript(javascript+xml)来处理,每个动作都要提交给服务器来操作后返回显示,很多时候简直是不堪忍受。Pb和delphi的那种年代真是一去不复返了。
    不知道以后jsf如何,因为客户端还是可以做很多东西的。
    view
      就servlet来说,也可以用作页面显示,没有什么意义,一般可以用作流程扭转,相对于Action。除了那些开源方案,界面一般都是jsp来做,直观简单。xml我没有弄过,就不说了。
    Controller
    现在很少有人直接在jsp页面里面嵌入业务逻辑和数据库访问代码了,都会用controller来表示,根据不同的动作来调用不同的业务逻辑。唯一有点意外的是看到webwork2中用action把controller和model结合表示,很方便和新颖,只是从来就没有用过webwork2。
    目前的mvc结构,为程序带来了灵活和复用的功能,但是分层毕竟是有代价的,很多时候需要去解决所带来的问题。
    J2EE体系已经比较成熟了,也总是在修修补补中不断前进。
    licy 2004.08.07 MSN:[email protected]

    写的不错,我也深有同感,作者把当前j2ee种存在的弱点和三层开发的困惑都说出来。不过,开发中(现实)很少有人能够理解。 特别是ejb 、全面oo、分布式,我就有点不感冒。我们的目的是开发出符合需要的应用,而从技术角度讲,无论任何发展中、有问题、不方便的技术都要去掌握。现在的客户很挑剔,他们不再挑剔应用,而是一味的赶时髦,什么新技术,无论是否掌握、是否实用,一定都要用到,老板也是如此。就像一个刚入门的编码者。不可否认,没有深入的应用,就没有发言权

Maybe you are looking for

  • Large File Size

    I am moving some AS2 code to AS3 in Flex. My SWF file size was 3 KB and is now 119 KB. So far, I'm unable to figure out what is causing all the extra bloat. Can someone take a look at my coding and see if they have any ideas? Download Project

  • Trouble copying videos to ipod

    when i connect my ipod to my computer, it updates my songs fine, but but it wont put my new videos on. i dont get an error message or anything, i just look in my videos on my ipod and they arent there... i know they're the right format, because i eve

  • Where Is The Content Source Name/Titles Stored In The SharePoint Database

    I am trying to tie my sharepoint crawl history (duration of crawls) with the content source.  the MSSCrawlHistory table has the data for calculating the durations but it doesn't give me the content source.  There is a column "crawlid" and "projectid"

  • My iPod is locked (stop to work) do 1 hour

    I was doing a Mobli, and it lock, do 1 hour and it don't answer nothing. I tried pressing the, place to load and nothing. Please help me.

  • Document Fonts folder missing

    Hi. When I package a document the Links Folder is there, but the Document Fonts folder is not. In the Package>> Font summary, ID says 15 fonts used, none missing or modified, but it doesn't list anything. I need to work on the document on another com