How to use application managed entity manager in EJB?

I finish reading The EntityManager Interface in JEE tutorial.
I know I can use container manager entity manager in EJB, but I want to explore how to use application managed entity manager in EJB.
Can I use application managed entity manager in EJB (container management JTA transaction is used)? Where do I should close entity manager if can?
The following is an example from JEE tutorial, but didn't find where to calose entity manager. and can I create mutiple EntityManagerFactory objects and Entity Manager objects to use them in a JTA transaction?
@PersistenceUnit
EntityManagerFactory emf;
EntityManager em;
@Resource
UserTransaction utx;
em = emf.createEntityManager();
try {
  utx.begin();
  em.persist(SomeEntity);
  em.merge(AnotherEntity);
  em.remove(ThirdEntity);
  utx.commit();
} catch (Exception e) {
  utx.rollback();

Seems like a very poor example, the whole power of EJBs is to use Container Managed Transactions so you don't NEED to manage the transaction and the entity manager yourself. What you posted is code I would expect in a non-JEE application, or in a piece of code which requires fine-tuned transaction boundaries such as batched data importing logic.
If I were you I'd research JPA in steps.
a) learn about JPA as an API outside of the scope of EJBs (recommended reading: the book 'Pro JPA 2')
b) learn about Container Managed Transactions in EJBs
c) learn about Bean Managed Transactions in EJBs
Right now you're rushing into c). I can understand that it raises many question marks at this point.

Similar Messages

  • How to use application to call a remote EJB?

    this is my code:
    package test;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.rmi.PortableRemoteObject;
    import java.util.*;
    import test.HelloWorldHome;
    import test.HelloWorld;
    public class callremoteEjb{
         public String callejb(){
              try{
                   Properties env = new Properties();
                   System.setProperty("org.omg.CORBA.ORBInitialHost", "202.120.80.219");
              System.setProperty("org.omg.CORBA.ORBInitialPort", "7001");
              env.put(Context.INITIAL_CONTEXT_FACTORY,
                             "com.sun.enterprise.naming.SerialInitContextFactory");
              env.put(Context.PROVIDER_URL, "t3://202.120.80.219:7001");
                   Context initial = new InitialContext(env);
                   Object objref = initial.lookup("HelloWorldBean");
                   HelloWorldHome home = (HelloWorldHome)PortableRemoteObject.narrow(
                                                      objref,HelloWorldHome.class);
                   HelloWorld helloBean = home.create();
                   return helloBean.sayHello();
              }catch(Exception ex){
                   ex.printStackTrace();
              return "aaa";          
         public static void main(String[] args){
              callremoteEjb testejb = new callremoteEjb();
              System.out.println(testejb.callejb());     
    i ' ve success deploy the EJB in the remote server.
    but it run error : " Can't find SerialContextProvider "
    how should i do?

    There is a sample called rmi-iiop. It has a Java applicationclient that talks to a remote ejb. Pl have a look at that.
    Sahoo

  • Problem with non-container managed entity manager

    i am working on a project, in which i am using entity beans.i use netbeans, glassfish as application server and toplink as persistence provider .
    i created a java class that handles all the operations with the entitys, which means i using non-container managed entity manager.
    in the constructor
    try{
                EntityManagerFactory emf = Persistence.createEntityManagerFactory("voidPU");
                entityManager = emf.createEntityManager();
            catch(Exception ex){
                throw new EJBException(ex.getMessage());
            }then i call a function in this class from a servlet
    the code of the function
    List users = null;
            try {
                ProgLanguages progLanguage = entityManager.find(ProgLanguages.class, languageId);
                users = (List) progLanguage.getUserIdCollection();
            catch(IllegalStateException illegalStateException){
                throw new EJBException(illegalStateException.getMessage());
            catch(IllegalArgumentException illegalArgumentException) {
                throw new EJBException(illegalArgumentException.getMessage());
            }i got an IllegalArgumentException saying Unknown entity bean class: class vanguard.server.entity.ProgLanguages, please verify that this class has been marked with the @Entity annotation
    what confuses me is that sometimes it works and most of the time it does not work, have i made anything wrong?, or there is a problem with any of the tools netbeans, glassfish, or toplink?

    Is it always the same entity that is reported as 'unknown' ? You mention that it works sometimes but is it the same deployment and the same code that works? The first thing I would verify is that the ear is being created as expected by netbeans. Check the persistence.xml file and verify that all of the classes are listed that will be used as entities.
    --Gordon                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to use application item in the page template

    How to use application item in the page template.
    Thanks,
    rajendra

    Hi,
    You can refer application item value in template like &MY_ITEM. (note period at end)
    http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35125/concept_sub.htm
    Regards,
    Jari

  • How to use application.getRealPath()

    Hi all,
    I need to retrieve a document which is external to .war file and with in the same server location. I dont want to hard code the file location path in my jsp. Is there any other alternative by using getRealPath() method. Pl let me know how to use application.getRealPath() if it makes any sense.
    Hoping to hear from you soon :)

    Say, doc1 is in webapps1 and you want to get its real path in webapps2. For that,
    in webapps2, you can use ServletContext.getContext("/webapps1") method , to get the context of webapps1. Then from this context, you can use context.getRealPath("/doc1") method to get the location of the document doc1.
    Hope this helps.

  • How to use Application Roles with Entity Framework

    How does one call sp_setapprole before a connection used by an Entity Framework object context closes, since the context opens and closes its own connection automatically, as needed? The only relevant event available on a store connection
    (DbConnection ) is StateChange , which does not include a
    ConnectionState of Closing . Attempting to call
    sp_setapprole when ConnectionState is Closed results in, "A severe error occurred on the current command. The results, if any, should be discarded."

    Yes, I realize that I need to call sp_setapprole on an open connection and that I can use
    ExecuteNonQuery or similar mechanisms. What I need to determine is how to do this
    automatically while using the entity framework.
    As I mentioned in my initial inquiry, the EF store connection, which is simply a DbConnection under the covers, does not expose an event (such as Closing) that would allow me to invoke
    sp_setapprole before a connection is closed. The only close event we are given is
    Closed , which is too late to do any good. I'm hoping to avoid burdening our systems with having to manually manage the connection.

  • Anyone know how to use the QuickTime Component Manager

    I have been reading that you can somehow enable the DV out in QuickTime to play video out via Firewire, but have had no luck. I guess by using the Quicktime Component Manager you can enable certain features and disable certain features. Does anyone have any idea on how to do this? Thanks everyone for the help.

    You can send a .dv file over Firewire (back to a camera for example) using iMovie.
    Maybe if your better explained your objective we could offer some suggestions.
    Many third party hardware devices can also be used to move .dv files to tape drives (like a VCR) or send the signal to broadcast devices.

  • Idea about how-to using 'Agilent Wireless Test Manager' interfaces in Labview ?

    Hello everyone,
    I am not sure whether it is appropriate to post this here.  
    Currently I got a Wireless Test Manager CD(Agilent E6560A) and is trying to convert some functionalities inside class 'cdmaTXMeasTests' into labview.
    I am doing the 'code domain power testing' module with labview, which is well done in that 'cdmaTXMeasTests'.
    I am wondering if any one could provide me some idea how to use that 'cdmaTXMeasTests' in my labview without rebuild the wheel.
    ( I am not sure whether that would work,  Are the libaries used by wireless test manager a  ActiveXDLL that could be used by labview ? Or there is some other way to do it or not?)
    Any idea is well appreciated,
    +Kunsheng Chen

    Good Afternoon Kunsheng Chen,
    It seems like you are trying to port your DLL.  Rather, I would suggest using a Call Library Function Node (right-click the Block Diagram, Functions>>Connectivity>>Libraries & Executables>>Call Library Function Node).
    From the Agilent website, this is a C dll so you will be able to access it using this VI in LabVIEW with no problems.  You might want to contact Agilent to see if this DLL has ActiveX components.  Alternatively, you can simply browse the list of ActiveX components on your computer.
    The following links may provide some useful information for using a DLL in LabVIEW.
    An Overview of Accessing DLLs or Shared Libraries from LabVIEW
         http://zone.ni.com/devzone/cda/tut/p/id/3009
    Call Library Function Node
         http://zone.ni.com/reference/en-XX/help/371361E-01​/glang/call_library_function/
    Using Existing C Code or a DLL in LabVIEW
         http://decibel.ni.com/content/docs/DOC-1690
    Regards,
    Charlie Piazza
    Staff Product Support Engineer, RF
    National Instruments

  • How to use Application Integrator (AI) in EP 710?

    Hi all,
    I can't find any entry points about application integrator in EP 710, does anyone know how to use it in EP 710?
    Thanks and regards,
    Bena

    Hi,
    first you need to check out in your system whether you have a par name com.sap.portal.howtos.webapp is available or not in you system templates.
    if it is not their then you need to upload it.
    to upload follow the steps
    goto system administration -> support -> portal runtime -> administration console
    -> browse throught the contents and fine your par file and press upload.
    after uploading go back to system administration -> system configuration -> system landscape -> portal content
    here you can create your own folder or right click on portal content directly to create system
    when you right click on folder or portal directly you will get three option,
    system from template, system from par and folder.
    you need to choose system from par and after choosing  in portal content you find
    par files selction screen here you need to goto the par com.sap.portal.howtos.webapp -> webapplication  which you imported or uploaded to your portal earlier.
    and then in new screen you need to enter the required fields such as name and id.
    after this save it and close the editor.
    then again got your system you created and right click on it and open object.
    here you set the object property in navigation as object is a template to yes.
    by setting this property you are making the system available on the template selection ie,.
    select system from template.
    you create another system using this system.
    here you have three steps to perform
    a) connection properties
    b) user management
    c) system alias
    in connection property here you need to set the url, http(s), and server name.
    since you are using sap logon ticket you need to select in user management property to UIDPW and since you are giving authorization to both user as well as end user you need to select admin,user.
    then for the system you need to select system alias, so that the end user can map with the system by choosing the alias you set. to set alias goto property editor and choose system alias and enter the name you want and press add.
    Now you goto user administrator and choose your user and select him and press modify and choose mapping tab and select the alias name you entered and and enter the mapped user id and mapped password.
    after mapping check the connection it should succeed.
    then create an iview to verify whether the iview created by this par is working fine or not.
    **********please reward points if the information is helpful to you***************

  • How to use application class reference in the controller methods of BSP

    Hi,
    I have created a bsp application and also created an application class and assigned it to the application class. In the application class, I have created attribute TEXT type string(public and instance parameter).
    In the controller let's say main.do, I am trying to give a value to to the text by adding the following code.
    application->text = 'test'.
    I am getting syntax error saying field 'text' is unknown. It is not contained in one of the specified tables nor defined by DATA statement. 
    Please can someone let me know how to use the application class in the coding with an example. I couldn't find how exactly this has to be reference. Please help.
    Best regards
    Siva

    Hi,
    if you are having main controller and sub-controller then you may need to use below coding to use application class reference.
    *Data declaration
      DATA:  obj_cntrl        TYPE REF TO cl_bsp_controller2,
             obj_sub_cntrl   TYPE REF TO z_cl_sub_cntl,
             application TYPE REF TO z_cl_application.
    *Get the controller
      CALL METHOD obj_main_cntrl->get_controller   "obj_main_cntrl is the object of main controller
        EXPORTING
          controller_id       = 'SUB'   "Controller ID
        RECEIVING
          controller_instance = obj_cntrl  .
      obj_sub_cntrl ?= obj_cntrl  .
      application ?= obj_sub_cntrl ->application.
    or simply use below code in your controller method.
      application ?= me->application.
    Thnaks,
    Chandra

  • How to use application params in .EAR files

    When we build an ear file , Weblogic-application.xml provides application-param
    tag?
    are they similar to env-entry in ejb-jar.xml.
    Can I use application-param tag to define a configurable params
    say myName and value as "Harshad"
    How do i read it in the application say a simple java class that is included in
    a jar inside the ear file.

    application-param tag in weblogic-application.xml may be used to define parameters:
    webapp.encoding.default
    webapp.encoding.usevmdefault
    webapp.getrealpath.accept_context_path
    http://e-docs.bea.com/wls/docs81/programming/app_xml.html#1034632
    "Harshad Nanal" <[email protected]> wrote:
    >
    When we build an ear file , Weblogic-application.xml provides application-param
    tag?
    are they similar to env-entry in ejb-jar.xml.
    Can I use application-param tag to define a configurable params
    say myName and value as "Harshad"
    How do i read it in the application say a simple java class that is included
    in
    a jar inside the ear file.

  • How to use Application Designer with virtual box vm's

    hi all,
    I could use some help please.
    I have everthing installed and working on the VMs but now I want to use Application Designer but I must be doing something wrong.
    I installed the Oracle client on windows and created tnsnames.ora. I can't connect to the database from windows to vm.
    I have some questions which might help me fix this.
    The directory that was mentioned to put tnsnames.ora in (C:\app\Mike\product\11.2.0\client_1\network\admin\) was not there so I had to create it. Was that what I was supposed to do or did the install go bad?
    For the windows host file what should the ip addresses be? I used the IP Addresses of the eth1 network interface from both guests which I created.
    As far as the PeopleTools on windows I used PT 8.52 but with no patch will that work even though the VMs are PT 8.52.06? So if I need the patch in order for App Designer to work how can I get the patch I think I need an account to do that. I think it mentions in the OVM doc that they are included somewhere so should I use those instead?

    <strike>With virtualbox vm's I assume that you mean the OVM templates converted to virtualbox.</strike>
    Didn't notice the OVM category :)
    Which Oracle Client installer did your use?
    You could use the following download from MOS for Database 11.2..02 (since Peoplesoft database is also delivered at 11.2.0.2)
    Patch 10098816: 11.2.0.2.0 PATCH SET FOR ORACLE DATABASE SERVER
    From the patch set download only p10098816_112020_platform_4of7.zip, which is your database client. The rest you will not need to be able to use Application Designer and Datamover.
    Once downloaded start the installer and choose option Runtime (do not choose Instant Client or Administrator).
    Now that you have your connectivity, you can start the PIA-AppBatch vm.
    switch to psadm2 user and go to $PS_HOME.
    Here you will find two files
    toolsclient.zip (PeopleTools 8.52, use client only)
    toolspatchvcd.zip (PeopleTools patch 8.52.06, , use client only)
    Copy these files to your windows workstation and install them in that order.
    Copy the tnsnames from the Database vm to your oracle client install dir network\admin dir and you should be ready to start using Application Designer/Datamover.
    For more detailed information see the post from Nicolas:
    http://gasparotto.blogspot.nl/2012/09/psovm-fscm-91-feature-pack-2.html
    http://gasparotto.blogspot.nl/2011/10/peopletools-852-client-installation.html
    Regards,
    Hakan
    Edited by: Hakan Biroglu on Mar 9, 2013 1:23 PM
    Edited by: Hakan Biroglu on Mar 9, 2013 1:30 PM

  • How to use Tuxedo's services from an EJB: Jolt x JET ?

    Hi.
    Can anyone tell me if an EJB MUST use JET (instead Jolt) to access Tuxedo services
    Suppose the following case:
    We have a client using JNDI service to obtain an EJB.
    In my client i invoke the appropriate methods to create a jolt session and to
    start a jolt transaction. My EJB Bean only call Tuxedo services (using Jolt).
    Will this application work ? Will EJB code use the transaction created by the
    client code ? Will a transaction context exist ?
    Thanks in advance.

    Hi Daniel,
    If you mean WebLogic Server 5.1 by WL 5.1 (instead of WebLogic Enterprise), then
    yes, you need to use Jolt until you upgrade to a later release of WebLogic Server.
    WTC wasn't fully supported until WebLogic Server 6.1 and later.
    The transaction context of the container Jolt is being used in is not extended
    to the Tuxedo system. Jolt can be used to start a new and separate transaction
    in Tuxedo, but that transaction and the containers current transaction will not
    be coordinated.
    I'm not sure what you mean when you say:
    The transaction management when using Jolt is realized for Jolt API.
    There is no relantionship between Jolt transactions and Tuxedo transactions.
    Is this rightThe transaction management when using Jolt is transaction management of
    the Tuxedo system you are talking to. Jolt is a client side API that uses a
    delegated model for transactions. So a transaction started with Jolt starts
    a transaction in Tuxedo, but does not affect the transaction context of the
    environment the client, i.e., the place where the Jolt call was made. So if
    you are using Jolt inside an EJB hosted in the EJB container of WebLogic
    Server, the Jolt calls will have no impact or effect on the transaction state
    of the EJB.
    Regards,
    Todd
    "Daniel" <[email protected]> wrote:
    >
    Ok.
    We have EJBs running in Weblogic and they are using Tuxedo services.
    We have used Jolt instead WTC because we are running WL 5.1. Can i
    use WTC with WL 5.1 ?
    The transaction management when using Jolt is realized for Jolt API.
    There is
    no
    relantionship between Jolt transactions and Tuxedo transactions. Is this
    right
    Thanks in advance.
    "Todd Little" <[email protected]> wrote:
    "Daniel" <[email protected]> wrote:
    Hi.
    Can anyone tell me if an EJB MUST use JET (instead Jolt) to access
    Tuxedo
    services
    ? You can use either Jolt or preferably use WTC and JATMI.
    Suppose the following case:
    We have a client using JNDI service to obtain an EJB.
    In my client i invoke the appropriate methods to create a jolt session
    and to
    start a jolt transaction. My EJB Bean only call Tuxedo services (using
    Jolt).Why is the client creating a Jolt session and transaction? They will
    not be associated
    with the EJB's execution. The client's Jolt context is not propogated
    to the
    EJB. Can you explain what it is you want to do? What do you want included
    in
    the transaction?
    Will this application work ? Will EJB code use the transaction created
    by the
    client code ? Will a transaction context exist ?Well I suppose it depends upon what you mean by work. It comes down
    to what are
    you trying to accomplish. The client is a WLS client? Is the EJB a
    client of
    some Tuxedo service? If those are both true, then you would be best
    served by
    controlling the transaction with the EJB's deployment descriptor and
    having the
    EJB use WTC to access Tuxedo. WTC will take of propagating any required
    transaction
    state to Tuxedo.
    Regards,
    Todd

  • How to use a native library (.so) in EJB

    Hi,
    I know how to package a native library into a connector in iAS. But I don't quite know how to use it. Suppose I provide a wrapper java class for the native library, can I use the java class directly in my EJB (since the classloader of the RA is the parent of the EJB classloader) or I have to issue an outbound call?
    Also, if I package the native library into a RA (standalone), iAS will automatically load it so in my wrapper java class, I don't have to call System.loadLibrary(...). Correct?
    Thanks,
    Haitao

    Thanks, Russ. My older Mac Pro is a 2,1 -- I think I only missed by a few months in buying one that would run Mavericks (64 bit EFI).  I do intend to buy a "trashcan" Mac Pro but not just yet.
    As for updating projects — that's my issue, I think. The Mac Pro and the laptop are networked so I can be working on my laptop and go to the Mac Pro and open the Final Cut Pro that is resident on that computer. What is odd is that it doesn't open any of the projects that normally open up with I start up FCP X on the Mac Pro.
    I frequently work inside the house on my laptop running programs that are on my Mac Pro outside in my office — usually no problem at all with Adobe applications. 
    FCP X won't let me open a project by clicking on the project — it insists that I "Open projects from within FCP X" but they won't open that way.  This what is odd — that it won't let me open projects even thought they are fully native to that version of FCP and are even on the same hard drive on the Mac Pro.

  • How to add applications of Agent-managed-Device

    Hello,
    we just can´t get the Application-Monitoring get to work. We followed dozens of guides and read hundreds of forum-posts about it but nobody seems to have our problem.
    So here´s the thing:
    We downloaded/installed the "Application Monitoring" MP.
    Klicking on the "Applications" view in this MP, there is no data shown.
    We sure know that you first HAVE TO add Applications, but
    HOW?
    There is no option in Authoring or Administration.
    You can´t even select which devices OM should scan for Applications.
    Before I forget: We do NOT want to monitor local processes.
    First, we got that to work and second, it´s pointless anyway(you can see with your bare eyes if a process is running or not...)
    Thanks in advance for your help guys! We are really lost here.
    P.S. We´re from Germany, so please excuse spelling-mistakes etc.

    Hi,
    What sort of monitoring do you want for your application?
    APM integrated to SCOM 2012 is only for managed applications (.NET and Java), and it also suits well (and actually is intended for this purpose) for your custom apps monitoring, not only for Microsoft apps as you wrote. But these should be .NET/Java-stack
    based apps.
    Except of APM SCOM provides more other monitoring capabilities, some of which could be used to monitor third-party unmanaged apps:
    - Web Application Availability Monitoring
    http://technet.microsoft.com/en-us/library/hh881883.aspx
    - Web Application Transaction Monitoring
    http://technet.microsoft.com/en-us/library/hh457553.aspx
    - GSM Monitoring
    http://blogs.technet.com/b/momteam/archive/2012/06/19/global-service-monitor-for-system-center-2012-observing-application-availability-from-an-outside-in-perspective.aspx
    - Windows Service Monitoring
    http://technet.microsoft.com/en-us/library/hh457595.aspx
    - Process Monitoring
    http://technet.microsoft.com/en-us/library/hh457551.aspx
    - Monitoring capabilities provided by specific MPs (for example, SharePoint 2010 MP, BizTalk MP, etc)
    http://unofficialsystemcentercatalog.wordpress.com/2012/12/27/operations-manager-is-there-a-management-pack-for/
    - etc
    As you see SCOM brings much, but APM, the current forum branch is dedicated to, is only for managed code apps, because it works as profiling wrapping the calls of your application. The profiling is not applicable to unmanaged (for example, plain C++)
    code.
    Igor Savchenko, VIAcode Consulting LLC (http://www.viacode.com/)

Maybe you are looking for

  • Why is Garmin & TomTom far better than directions from Siri

    My first smart phone is my iPhone 5S. I live in NYC. When I ask for directions, it takes me to the toll bridges and tunnels via the route with the most traffic. She never heard of the 59th St aka Queensboro aka Edward Koch Bridge. It took me to Stapl

  • How to make group contacts

    Need help with setting up a group of contacts to my phone. Need to be able to send group e-mail and texts

  • HT204053 icloud won't sync between computers

    I bought a film using my apple ID on my laptop, and it won't download on my other machines (mac Mini at home, iPhone, iPad) although I connect with the same Apple ID. Can you help?

  • Error of passing of oracle.sql.ARRAY in PL/SQL function at work under OC4J

    Oracle Application Server Containers for J2EE 10g (9.0.4.0.0) Error occured at working with DataSource based on com.evermind.sql.DriverManagerDataSource and oracle.jdbc.pool.OracleDataSource. Error: java.lang.AbstractMethodError: com.evermind.sql.Orc

  • Webutil give me ora-06508

    Hi, i ran webutil demo and the screen show ok, but when i press the button GET_CLIENT_INFO appear the message when button pressed ORA-06508 and not read the procedure .... Regards