Shay Shmeltzer's Oracle Development Tools Tips

  • January 22, 2009

Insert & Update for JPA/EJB 3.0 with ADF binding

Shay Shmeltzer
Director of Product Management - Oracle

One thing that we don't show in the basic JPA/EJB 3/JSF/ADF Faces tutorial for 11g is how to do an update or an insert into the database.

(We do show how to do an update in the cue cards tutorial).

As a fast solution to a question that poped up on OTN about this I created this short demo that shows you how to do this - all of course without a single line of code.

I'm just using default JPA entity on the Departments table, and the default session facade EJB that JDeveloper created for it. Then using the ADF binding layer to create the page that will let you do insert and updates.

Join the discussion

Comments ( 14 )
  • James Bayer Monday, January 26, 2009
    What's with the Chicken and Egg search in your google search bar in the recording? Just kidding that's not a serious question, I always love looking at the desktop detail in these communication formats and find myself taking out tabs, cropping the capture area, etc before I record a screenshot or screencast. I like screentoaster, it's a good tool for this type of quick demo. Thanks for the example.
  • shay Monday, January 26, 2009
    Hi James, nice catch - I needed a chicken and egg image for a slide I was working on. As this shows - I tend to multitask, so while working on the slides I figured out I can quickly record something to explain a solution to someone on OTN.
    In the future I'll try and clean up my desktop - the way I do for official OTN demos.
  • Sylvain Kemtchouang Sunday, October 4, 2009
    Pretty simple and understanble.
    Thanks a lot for the tip.
  • Fabio Sunday, March 14, 2010
    I am getting this error when I tried this demo:
    Messages for this page are listed below.

    Unexpected exception caught: javax.ejb.EJBException, msg=EJB Exception: : java.lang.IllegalArgumentException: Object: null is not a known entity type. at org.eclipse.persistence.internal.jpa.EntityManagerImpl.mergeInternal(EntityManagerImpl.java:322) at org.eclipse.persistence.internal.jpa.EntityManagerImpl.merge(EntityManagerImpl.java:304) 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:597) at
    What am I doing wrong ?
  • shay.shmeltzer Monday, March 15, 2010
    There is a known problem doing this with the results of a named query - there is also a simple workaround - see here: http://blogs.oracle.com/shay/2010/03/solving_null_entity_problems_w.html
  • gülru Wednesday, August 18, 2010
    Hi Shay, that demo is the only thing I need now but there is no video. I open the page in different browsers but it doesn't seem anyway.
  • shay.shmeltzer Thursday, August 19, 2010
    This is a youtube video - so make sure that Flash is installed.
    You can also watch the video on my youtube channel here:
  • Mike Adam Thursday, July 14, 2011

    Do you have a demo on how to do create/edit/delete records with TABLES instead of forms?

    I don't know how the FORM is even useful, since if you have anything more than about 10 records in the particular data table, using Next and Previous buttons to navigate is extremely tedious. How do you get to record 234345 of 1000000 records?

    When I try to use tables, I cannot drop the Create operation button ANYWHERE. If I find a place to drop it somewhere outside the table, its connection to the table doesn't exist, and the button produces an error report of empty required fields (useless).

    I've been struggling to use JDeveloper for several weeks now, without any progress. I'm at my wit's end with it, and I'm seriously considering trying another tool, and just getting rid of this. I don't see how this is supposed to be a Rapid App. Dev. tool. Every step takes hours and hours of research to accomplish, and even then the results are never what I want. I think I could get a better result using Visual Studio. I might have to make every piece of low-level code from scratch and take months to develop a simple CRUD application, but at least I can move forward.

    Please help!


  • shay Thursday, July 14, 2011

    Mike, are you looking specifically for a demo that uses JPA/EJB in a table layout?

    A few points - about where to drop the buttons - I would suggest surrounding the table with a panelCollection and then creating a toolbar in the designated facet and dropping the buttons there. The buttons should of course be related to the operations of the specific data control.

    As far as using a table vs a form in cases where you have a lot of records - Frankly I would hate to be the guy that needs to scroll a table to find record 234345 out of 1000000 - instead I would recommend using a query component to filter the records, and then showing a list of the results in a table. Then when you click a specific record show it in a Form below the table (or in a pop-up to edit it).

    Check for example how the edit is done here: http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/JPAdemo/JPA_demo_mp4.html

  • Mike Adam Monday, July 18, 2011

    I think one problem is I don't have a SessionEJBBean.java file like yours. Mine does not have mergeEntity and persistEntity methods. How do you create this source file? I'm not sure why your demo starts with that part already assumed.

    From there, I could create the Data Control and have mergeEntity and persistEntity methods to work with. Then I could probably actually follow your demo

    Could you direct me to a link or explain how you got SessionEJBBean.java the way you have it?

  • Shay Monday, July 18, 2011

    Mike, JDeveloper can generate this session bean with the merge/persist and other methods for you, when you indicate to JDeveloper to create the session bean as a Facade for JPA.

    See this tutorial: http://download.oracle.com/docs/cd/E18941_01/tutorials/jdtut_11r2_51/jdtut_11r2_51_1.html for example.

  • Mike Adam Monday, July 18, 2011


    I had made a few mistakes before.

    For one, I had dragged the tables from the database connection to the EJB Diagram, instead of the *.java files under the Model project.

    Another was that, although I knew before that a Panel Collection wraps around the ADF Table, I saw a Facet Toolbar in the Panel Collection, and didn't realize I actually had to drop a Toolbar into the Facet Toolbar so that buttons could be dropped in there (although you already told me that before).

    So I have Create, Insert, and Save buttons (Insert is for Create [persist<Table> method] and Save is for a modified record [merge<Table> method]).

    A problem though: I can't seem to update the table after an Insert or Save occurs. I have Before Insert Triggers in the Oracle database, which generate a Primary Key, and Create and Update Date values for the new/updated record. I can see using SQL Plus that the triggers are working and the data is being altered correctly, but I wish I could get those values to reflect back to me in the table after the insert/save has completed.

    Thanks for your continuing help, Shay. Now that things are starting to work, I can see this is a powerful tool. The Javascript controls, like the table, with its sorting, filtering, and column rearrangement abilities, are very impressive.


  • Shay Monday, July 18, 2011

    Mike - you might need your save button to also call an execute method to re-query the data from the database into the table and reflect the changes.

    This blog shows you how to have one button that does two operation


    - in your case it will be the persist and the execute operation your can find under your collection.

  • Mike Adam Monday, September 19, 2011

    Thanks Shay.

    I got that to work (using the Execute operation after each Insert/Save/Delete operation). But this only works for single tables. If I have a master/detail view with 2 tables, the Execute method on the detail table doesn't seem to work. And I can't find a solution to this anywhere.

    I create two ADF Tables independently, each within its own Panel Collection. The master table is created by dragging the DepartmentsFindAll view object from the business services, and the detail table is created by dragging the EmployeesList view object, which is a direct child of the DepartmentsFindAll view object used for the master table.

    Listing the master table's ID in the detail table's PartialTriggers property makes it so that selecting a record in the master table updates the detail table to list the detail records of that selected master record. That works fine.

    All other operations for the detail table work fine:

    Create (CreateInsert operation for EmployeesListIterator),

    Insert (persistEmployee method for ProjectFacadeLocalIterator with parameter bindings.EmployeeListIterator.currentRow.dataProvider),

    Save (mergeEmployee method for ProjectFacadeLocalIterator with parameter bindings.EmployeeListIterator.currentRow.dataProvider), and

    Delete (removeEmployee method for ProjectFacadeLocalIterator with parameter bindings.EmployeeListIterator.currentRow.dataProvider).

    I create the Refresh/Execute operation like the Create operation:

    (Execute operation for EmployeeListIterator).

    It seems to refresh the table, but doesn't requery the results. Is it referring to the wrong iterator or something? It's the same one I use for the other operations. Even checking the 'Apply to all iterators in page definition' checkbox in the Edit Action Binding dialog doesn't work. And using that checkbox setting causes the table synchronization to get screwed up, so that selecting a master record no longer lists the detail records for that selection. Clicking the master table's Refresh/Execute button fixes the synchronization.

    Please help.

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.