Persisting serialized bean in EJB 3.0

Hello,
I'm seeing some surprising results in EJB 3.0 when executing an update to some bean that is unmarshalled from a remote client. Perhaps I'm misunderstanding the API, but I reached the conclusion, from documentation and various online discussions, that merge() could handle this need - but it does not. An exception is thrown.
Via the EntityManager API I can't update a bean that's being constructed from a remote payload. However, if I access the underpinning Toplink Session, I can use its API to execute an update via the unmarshalled bean. So, I'm able to satisfy my need, but I'm a bit surprised in how I have to do it. It seems surprising to me that the public API of EntityManager wouldn't support it, and, instead, I have to navigate to the Toplink API for its mergeClone API. Am I misunderstanding or misconfiguring something?

Post your update code.

Similar Messages

  • Local session bean lookup in another local session bean in EJB 3.0

    Hi,
    I am doing JNDI lookup of a local session bean in a session bean. ( I do not want to use EJB dependency injection).
    Lookup of local interface from session bean is successful. But, when the calling session bean is a local session in another session bean, the lookup fails.
    Here is an example:
    @Stateless
    @EJBs({@EJB(name="EJB2Local", beanInterface=EJB2Local.class),
    @EJB(name="EJB3Local", beanInterface=EJB3Local.class)})
    public class EJB1 implements EJB1Remote, EJB1Local{
    public void findEJB3Local(){
    //1. JNDI lookup for EJB3Local ----
    //2. EJB3Local.someFunction()
    @Stateless
    @EJB(name="EJB1Local", beanInterface=EJB1Local.class)
    public class EJB2 implements EJB2Remote, EJB2Local{
    public void findEJB1Local(){
    //1. JNDI lookup EJB1Local
    // 2. Call EJB1Local.findEJB1Local method
    //THIS METHOD CALL WILL FAIL.
    public void findEJB1Remote(){
    //1. JNDI lookup EJB1
    / 2. Call EJB1Local.findEJB1 method
    @Stateless
    public class EJB3 implements EJB3Remote, EJB3Local{
    public void someFunction(){}
    This setup was working in EJB 2.1, as we had clear ejb-local-ref definitions in our ejb-jar.xml file.
    I am suspecting that EJB 3.0 has special annotation to use when lookup is made from another local session bean.
    Any comments will be appreciated.
    Thanks,
    Mohan

    From a private component environment perspective, declaring @EJB in a bean class is equivalent
    to using ejb-ref or ejb-local-ref for that same bean in ejb-jar.xml. In each case, the EJB dependency
    is declared for that bean. Each EJB component has its own private component environment, so
    code running within invocations on different EJBs can not see the component environment of the
    components that made the invocations.
    What exact error are you getting? Please post the stack trace if possible.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Persist Entity Bean in flat file?

    Is it possible to persist entity bean in a flat file? I need to persist a single value (sequence number) and I can not use database to do so.
    I would need to run this in a clustered environment and need to recover the value if something goes wrong. The statefull bean would almost do except when one server fails before it replicates value onto another box.
    thx.

    Steve Edens wrote:
    I'm also trying to get a grip on the best way to handle some static application properties in a clustered environment. My need mostly relates to
    a need to read in some flat file type properties and then store them someplace
    where business logic can call them as needed.. Like a static hashmap or
    something. But someone mentioned Entity beans, BMP, etc..
    Now.. here's the strange part of the message.
    Back in 1999 I traveled over to our west coast office in San Francisco. I was meeting and greeting the staff there and along the way I had a short
    meeting with someone named Bisera Ferrero. I mention this event because I
    was really impressed with the beauty and charm of Bisera. Therefore, I guess
    I'm a fan. I rememered the name.. a little. Really, I had sort of forgotten
    about it until reading this forum this morning. So.. who knows. I guess
    there could be a lot of Bisera Ferrero names on our planet.
    Good luck in your quests..

  • Need of session bean in ejb?

    We can have the session beans business logic in Servlet using some support class(may be bean).I would like to know exact purpose & use of session bean in ejb specification.

    We can have the session beans business logic in
    Servlet using some support class(may be bean).I would
    like to know exact purpose & use of session bean in
    ejb specification.You can think of a SessionBean as a script. It handles certain business logic, for example, like book a flight. It might get the itinerary, charge the credit card, book a flight, etc. Usually, it is used as a facade, or front to one or more entity beans.
    Now, you could do these exact same things with servlets, but the session bean allows you to have:
    1. A single transaction scope. If one of your processes throws an exception and you've updated, for example 2 database tables, this transaction can be rolled back and everything will be consistant.
    2. Servlets, by nature, are threaded and you have to take special care with synchronization issues of any member variables that you may use in the servlet. With EJBs there are no synchronization issues.
    3. Security. You can specifically disallow/allow access to methods based on roles that you define.
    These are the big reasons for using EJBs. Yes, you can do all of this with servlets, but you'd have to do it yourself ... but why do it, if it is already done for you.
    I hope that that clears things up.
    Regards,
    Paul

  • Difference between simple beans and EJB

    Anybody knows... the difference between the simple beans and EJB... Pls share with all. thanks a lot.

    The Verrrrrrrrry short scoop is that JavaBeans pretty much just adhere to a standard format, mostly getters and setters. EJBs work only within a specific framework - an EJB container, and have access to J2EE support. For a detailed look at EJBs, see my tutorial Getting Started with Enterprise JavaBeans Technology at the developerWorks Java zone:
    http://www-106.ibm.com/developerworks/edu/j-dw-java-gsejb-i.html
    Joe Sam
    Joe Sam Shirah - http://www.conceptgo.com
    conceptGO - Consulting/Development/Outsourcing
    Java Filter Forum: http://www.ibm.com/developerworks/java/
    Just the JDBC FAQs: http://www.jguru.com/faq/JDBC
    Going International? http://www.jguru.com/faq/I18N
    Que Java400? http://www.jguru.com/faq/Java400

  • CMP Entity Bean with ejb-ql finder methods and INFORMIX database

    Hi,
    I have some CMP Entity Beans with finder methods defined in ejb-ql. In my ejb-jar, within <entity> definitions I have something like:
        <entity>
          <abstract-schema-name>BeanName</abstract-schema-name>
          <cmp-field><field-name>fieldOne</field-name></cmp-field>
          <cmp-field><field-name>fieldTwo</field-name></cmp-field>
          <query>
            <query-method>
              <method-name>findAll</method-name>
              <method-params></method-params>
            </query-method>
            <ejb-ql>SELECT OBJECT(o) FROM BeanName o</ejb-ql>
          </query>
        <entity>
    And in persistent.xml:
    <db-properties>
         <data-source-name>datasource_name</data-source-name>
    </db-properties>
    <entity-bean>
         <ejb-name>BeanName</ejb-name>
         <table-name>table_name</table-name>
         <field-map key-type="NoKey">
         <field-name>fieldOne</field-name>
         <column><column-name>column_one</column-name></column>
          </field-map>
         <field-map key-type="NoKey">
         <field-name>fieldTwo</field-name>
         <column><column-name>column_two</column-name></column>
          </field-map>
          <finder-descriptor>
              <method-name>findAll</method-name>
              <method-params/>
         </finder-descriptor>
    Once deployed, on server side, I can found a java source file (with corresponding compiled class file) in path:
    j2ee/cluster/server0/apps/companyName/MyEARApp/EJBContainer/temp/temp38837373733/route/to/package/
    with names:
    BeanName0_0pm.java
    BeanName0_0PM.class
    and the generated java file contains this code:
      public java.util.Enumeration ejbFindAll() throws javax.ejb.FinderException, javax.ejb.EJBException  {
        TransactionContext tc = pm.getTransactionContext();
        Connection conn = null;
        PreparedStatement pSt = null;
        ResultSet ejb_rs = null;
        int status = javax.transaction.xa.XAResource.TMSUCCESS;
        try {
          conn = pm.getConnectionForFindMethod();
          pSt = conn.prepareStatement("SELECT \"O\".\"COLUMN_ONE\",\"O\".\"COLUMN_TWO\", FROM \"TABLE_NAME\" \"O\"");
          ejb_rs = pSt.executeQuery();
    I'm trying to call this method but it throws a SQLException when preparing the statement.
    It seems that Informix does not like this SQL syntax because of upper case names, doble quotes on table alias, or something else.
    When editing persistent.xml in netweaver, I can define the element <datasource-vendor> as ORACLE, SAPDB, MS_SQL_SERVER, DB2_UDB_AS400 or DB2_UDB_OS390 but INFORMIX is not an accepted value.
    Is there any way to define how this SQL query is build?
    Thanks in advance.

    The return type of the finder method defined in the remote home interface is either the entity bean's remote interface or a collection of objects implementing the entity bean's remote interface. The return type of the finder method defined in the local home interface is either the entity bean's local interface or a collection of objects implementing the entity bean's local interface

  • Application scope bean Vs. EJB

    I want to cash some application data - and was thinking of using a singleton bean with application scope in my controller and JSP page.
    <jsp:useBean id="myBean" scope="application" class="bean.datacash" />
    I am not very familiar with EJBs - and wanted to know if it would be a mistake not to use an EJB to perform that task.
    Is there a downside to my approach?
    Thanks for any insight
    Mike

    Entity EJB'S are used as a kind of data persistence, mostly to Databases. In a way it's like a kind of cache but any changes you make to an EJB are usually persisted to the underlying data storage on a regular basis.
    Session EJB's are more for business logic and depending on the type of Session Bean you use can either remain persisted in a session state or used and thrown away.
    EJB's also require alot of code so depending on your application requirements it is kind of a big decision.
    Is the data your wanting to cache to be shared by all users using the application? Are there any race conditions that may be met by concurrent access to the data? What do you plan to do with the cached data store it in a database or just make it available to share?
    If you want to look into using EJB's then your going to require an EJB Container to run them in (this can be standalone like OpenEJB or as part of an J2EE Application server like JBoss or Oracle Application Server to name just a couple).
    Using the Singleton Javabean can keeps things simple but once you start to synchronize methods with multiple users you can find some slowing down of the logic as the singleton tries to complete a request before getting onto the next.
    The [url http://jakarta.apache.org]Jakarta team offer a package called commons pooling which is designed as a pooling framework (also a way of caching) that can come in handy, I've used it to create a custom JDBC Connection pooler and it works quite well when you get the hang of it.
    Another thing to consider is the load the application may be under at it's busiest time. How many concurrent users do you expect to access the application?
    Sorry I can't give you a real answer as that is entirely up to you and your requirements. If you have a small app that has around 20-50 users then EJBs are bit of an overkill. If you find you'll have 100+ users with lots of data to manage then EJB's are probably a good option.
    If you have a look at [url http://www.theserverside.com]the serverside web site you may find a couple of articles on data persistence or check out some of the online magazines which also have articles on this same topic.
    Anthony

  • Persistance of beans in JSF-based sites

    I'm new to Java EE 5, so take it easy on me. I'm trying to learn some Java EE stuff, focusing first on JavaServer Faces. I've got an idea for a little site I want to build as part of my learning process, but there's one thing I haven't figured out how to do.
    I basically want to make a few JSF pages with some persistent beans. Can JSF-managed beans be made persistant? Can JSF use EJBs as JSF-managed beans? What's the best way to do all of this?
    Thanks in advance.

    ya i have declared even my console says the init of the jsp file is successful.
    so i could reach to the jsp but it is not able to instantiate the bean managed class. also the stacktrace says cannot find that class even though the compiled .class file is in classes folder inside WEB-INF.
    thanx,
    Karthik

  • Calling Enity Bean's business methods from a session bean in EJB 3.0 specif

    Hello everybody,
    Happy to be a member with you in this forum.
    This is my first participation in this forum.
    I have some problem to start with EJB 3.0 specification, I have created an entity bean with some business methods that access a mysql datbase, then i want to create a stateful session bean to provide the client an interface to consume business methods in Enity be
    Please can someone you help me with an example

    @Vladimir Pavlov
    I did not understand what you are trying to convey...
    Whenever an attribute of this bean is modified we want to access that latest value.... Is there any way to know, when the attribute is modified? Just with get/set we can not know, when it is modified... am i right?
    We want to achieve this without modifying the existing source code of the EJB....
    @ Ivo Simeonov
    As of my knowledge, to use interceptors we need to modify the EJB source code, but we do not want to touch the source code....
    All this has to be achieved dynamically when the application is deployed in the production.... is it possible???

  • Local Session Bean calling another local Session Bean in EJB 3.0

    Hi,
    In EJB 3.0, I am trying to do JNDI lookup of a local sesion bean from another session bean's helper class.
    I am not using @EJB injection mechanism here, as call to the local session bean is made in a helper class. Helper classes do not support resource injection.
    Following are the EJB class definitions used in my project. Call to "EJB3Local" made from "EJB1" fails as the "EJB2" helper class is calling "EJB1Local"
    @Stateless
    @EJBs({@EJB(name="EJB2Local", beanInterface=EJB2Local.class),
    @EJB(name="EJB3Local", beanInterface=EJB3Local.class)})
    public class EJB1 implements EJB1Remote, EJB1Local{
    public void findEJB3Local(){
    //1. JNDI lookup for EJB3Local ----
    //2. EJB3Local.someFunction()
    @Stateless
    @EJB(name="EJB1Local", beanInterface=EJB1Local.class)
    public class EJB2 implements EJB2Remote, EJB2Local{
    public void findEJB1Local(){
    //1. JNDI lookup EJB1Local
    // 2. Call EJB1Local.findEJB1Local method
    @Stateless
    public class EJB3 implements EJB3Remote, EJB3Local{
    public void someFunction(){}
    A remote call to EJB2.findEJB1Local() will invoke EJb1Local.findEJB3Local method and the call fails with "java:comp/env/EJB3Local" not found in EJB1Local.
    Has anybody encountered an issue like this issue with local interface calling another local interface?
    Thanks,
    Mohan

    To refer a Ejb from another Ejb include <ejb-ref> element
    in ejb-jar.xml
    <session>
    <ejb-name>SessionBeanA</ejb-name>
    <ejb-ref>
    <ejb-ref-name>SessionBeanB</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <home>com.ejb.SessionBeanBHome</home>
    <remote>com.ejb.SessionBeanB</remote>
    </ejb-ref>
    </session>
    Include a <reference-descriptor> in weblogic-ejb-jar.xml
    <weblogic-enterprise-bean>
    <ejb-name>SessionBeanA</ejb-name>
    <reference-descriptor>
    <ejb-reference-description>
    <ejb-ref-name>SessionBeanB</ejb-ref-name>
    <jndi-name>com.ejb.SessionBeanBHome</jndi-name>
    </ejb-reference-description>
    </reference-descriptor>
    </weblogic-enterprise-bean>
    In SessionBeanA Bean class refer to SessionBeanB with
    a remote reference to SessionBeanB.
    InitialContext initialContext=new InitialContext();
    SessionBeanBHome sessionBeanBHome=(SessionBeanBHome)
    initialContext.lookup("com.ejb.SessionBeanBHome");
    SessionBeanB sessionBeanB=sessionBeanBHome.findByPrimaryKey(primarykey);
    sessionBeanB.update();
    sessionBeanB.getAll();
    thanks,
    Deepak

  • EJB 2.1 session bean calling EJB 3 session bean?

    I have a WL 10 (JDK 1.5/EE 5) server that has several EJB 3 stateless session beans deployed and working well. But now I need to allow a JBoss 3.2.3 (JDK 1.4) EJB 2.1 session bean make remote calls into these EJB 3 EJBs. Can this even work?
    It seems to me that EJB 3 calling EJB 2 would be fine, but not in the reverse?

    I have a WL 10 (JDK 1.5/EE 5) server that has several EJB 3 stateless session beans deployed and working well. But now I need to allow a JBoss 3.2.3 (JDK 1.4) EJB 2.1 session bean make remote calls into these EJB 3 EJBs. Can this even work?
    It seems to me that EJB 3 calling EJB 2 would be fine, but not in the reverse?

  • Stateful Session Bean Initialization (EJB 3.0)

    Hi all!
    In EJB 2.1 the initialization was with create (args) methods. NOw, how is it exploited? Create methods are no more there and there must be a way to send parameters to the stateful session bean when it is newly created...isn't it?
    Thank you!

    There is no pre-defined equivalent of a create method in EJB 3.0. If you want to initialize a
    stateful session bean, just define a business method that the client should use as an initialization
    method.

  • Can i call Bean managed EJB with transaction attribute Required New

              I am calling a BeanManaged EJB which has a transaction attribute
              set to Required New from a container managed bean. Does it create a new transaction
              other than the Bean managed transaction. Do i really need a required new field
              transaction attribute.All i need is user controlled transaction.Do i need to set
              the transaction aatibute.
              Thanks
              Krish.
              

    Hi Krish,
              The question does not make much sense.
              I would suggest that you set all your tx settings to "Required" unless you
              have a specific reason to do otherwise, and in those few instances that you
              have a specific reason to do otherwise, then change it in just those places.
              Peace,
              Cameron Purdy
              Tangosol Inc.
              << Tangosol Server: How Weblogic applications are customized >>
              << Download now from http://www.tangosol.com/download.jsp >>
              "KRISH" <[email protected]> wrote in message
              news:[email protected]..
              >
              > I am calling a BeanManaged EJB which has a transaction attribute
              > set to Required New from a container managed bean. Does it create a new
              transaction
              > other than the Bean managed transaction. Do i really need a required new
              field
              > transaction attribute.All i need is user controlled transaction.Do i need
              to set
              > the transaction aatibute.
              >
              > Thanks
              >
              > Krish.
              >
              

  • Bean-Managed Persistent Entity Bean - SDA

    Hello,
    I wrote a BMP Entity Bean and it should use a data dictionary that i already have defined, but i do not know what should i write in the ejb-jar.xml file in order to get it works. Could you please tell me what should i write?
    <resource-ref>
      <res-ref-name>???</res-ref-name>
      <res-type>????<res-type>
    </resource-ref>
    Thanks for your help,
    SAPLernen

    Hello,
    I wrote a BMP Entity Bean and it should use a data dictionary that i already have defined, but i do not know what should i write in the ejb-jar.xml file in order to get it works. Could you please tell me what should i write?
    <resource-ref>
      <res-ref-name>???</res-ref-name>
      <res-type>????<res-type>
    </resource-ref>
    Thanks for your help,
    SAPLernen

  • How to intantiate Stateful session bean in EJB 3 ?

    In EJB 2.x, to instantiate a Stateful Session bean the process was:
    1. Lookup Home object
    2. call create(args) method on Home, that in turn would call corresponding ejbCreate(args) on the bean implementation.
    Now, in EJB 3, there is no concept of Home interaface, How can I instantiate a stateful session bean with some initialization parameters.
    Thanks

    Just the spec. NetBeans should only be providing the ability to add an ejbCreate method if the bean exposes a Local or Remote 2.x view.
    Each lookup or injection of a stateful session bean results in a new bean instance. As long as you call your methods to populate the additional
    state right after first acquiring the stateful session bean reference it will work.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for