Registered objects with Unit of work

Hi,
I am using the following code for persisting some data to the database. I register the following objects with the UOW obtained. If there is any exception with the business rules method(shown below) , the code uow.commit() is never invoked.
My question here is what happens the registered objects in that uow if commit is never invoked.
Any help will be appreciated.
Thanks
Priya
node=(DeviceNode) uow.registerObject(node);
station=(Station)uow.registerObject(station);
user=(User)uow.registerObject(user);
//Call a method to do some businees rules check
startWork(node,station,user);
uow.commit;

It depends on how you set things up. If you are managing the connection directly via Toplink (no pooling or containers or transactions), then if you dont commit, it doesnt save. If you are using JTS, registering the object will save it to the database barring any unchecked exceptions.
Zev.

Similar Messages

  • Issues updating with Unit of Work

    Hello,
    I think, I might be missing a point about toplink. I know that when I need to update an Object, i find the current object in cache(ReadObject) and then register that object to get a cloned object and do updates on the cloned object and then commit it.
    Everything works fine in above scenario, IF AND ONLY IF, I set the attributes of the cloned object individually. But the update doesn't work if I set the cloned object to a totally different object (clonedObj = otherObj) Here otherObj has changed attributes which i want to be updated. Toplink somehow doesn't like it.
    How do i do it?
    Sample working code:
    public void mergeData(Object obj, Class c){
    try{
    ReadObjectQuery query = ReadObjectQuery(obj);
    // get the object with the primary key as the one passed in
    Object persistableObject = session.executeQuery(query);
    Object objectClone = tx.register(persistableObject);
    //It is a User object
    ((User)objectClone).setName("New Neeraj");
    tx.commit();
    Sample NOT working code
    public void mergeData(Object obj, Class c){
    try{
    ReadObjectQuery query = ReadObjectQuery(obj);
    // get the object with the primary key as the one passed in
    Object persistableObject = session.executeQuery(query);
    Object objectClone = tx.register(persistableObject);
    objectClone = obj //passed in object
    tx.commit();
    Is it becuase of the ReadObjectQuery using the same object as used to set up the cloned object?
    Thanks in advance for the help.
    Regards,
    Neeraj

    Don,
    This is what the documentation says related to mergeClone:
    "Merge the attributes of the clone into the unit of work copy. This can be used for objects that are returned from the client through RMI serialization (or another serialization mechanism), because the RMI object will be a clone this will merge its attributes correctly to preserve object identity within the unit of work and record its changes. The object and its private owned parts are merged."
    What is the significance RMI and serialization in this.
    I tries mergeClone locally (using the UOW) and it works fine, but just want to make sure that I understand what the documentation says.
    Also, if you will be kind enough to explain the difference between mergeClone and mergeCloneWithReferences.
    Thanks,
    Neeraj

  • TopLink Article HowTo Manipulate objects using Unit of Work

    http://www.oracle.com/technology/sample_code/tech/java/codesnippet/toplink/unitofwork/readme.html
    My questions are:
    What is the var aSession and where is it declared. Where is this code, on the class created by toplink or the class that is tied to the JSP? How can you click an add button on the jsp and get the data to add to the database?
    It seems all the code and example on this site are missing, is there any reference that should you how to build a JSF app with jdev from start the finish?
    Thanks

    http://www.oracle.com/technology/sample_code/tech/java/codesnippet/toplink/unitofwork/readme.html
    My questions are:
    What is the var aSession and where is it declared. Where is this code, on the class created by toplink or the class that is tied to the JSP? How can you click an add button on the jsp and get the data to add to the database?
    It seems all the code and example on this site are missing, is there any reference that should you how to build a JSF app with jdev from start the finish?
    Thanks

  • Scale Object with Panel, but what about inside a Tab control?

    The Scale Object with Panel option works very well for simple UI
    objects.  I like to use it for VIs that display tables or
    multicolumn listboxes, etc.  I am finding a limitation when I use
    the Tab control.  If I have a table or listbox in each tab, I
    would like them to scale with the panel.  I would also like the
    tab to scale.  It should look like an Excel workbook where all
    sheets scale with the window even though they are each on their own
    tab.  If I could only Group the various tables / lists with the
    Tab itself....
    This wouldn't be such an issue if the Bounds property of the
    multicolumn listbox was writable.  I can set the number of rows
    and columns, but column size can be variable and not uniform across all
    columns.  Also, that solution looks and behaves much different
    from the Scale Object with Panel approach.... not to mention the extra
    coding required.
    I'm guessing that this amounts to a feature request, but if anyone has a present-version workaround, I'd love to hear about it.
    See you at NI Week!
    Dan Press
    PrimeTest Automation

    Hi Kalin T,
    Thanks for your prompt reply. I am running version 8.01. My problem is that i cannot select "Scale object with pane" for the controls inside a Tab control if the Tab control "Scale object with pane" is turned on. I want both the Tab control and the controls inside to be scaled, for instance an Waveform graph or an textbox  when i resize my main window.
    Best regards,
    Mattis
    Attachments:
    Scale.vi ‏11 KB

  • Insertion using objects and update using queries in a single unit of work

    HI All,
    I have a set of objects that i want to insert and then perform some update queries ( direct queries ) on the inserted data in the same transaction. but when i register the objects and execute the update SQL's on the same data in a same unit of work, the update statements are executed first and then the inserts are happening, I've also tried with child unit of work and parent unit of work but the result is the same.
    Can any one suggest a way to do object insertion and sql updates in a single transaction, Thanks in advance
    Regards,
    Sai Krishna

    The UnitOfWork is an abstraction for the physical database query. By default nothing is actually written into the database until the UnitOfWork commits. This means making updates to new objects involves modifying them in-memory and then the updated values will be included in the INSERT during commit.
    If you are having difficulty finding the newly created objects you can enable the query conforming capabilities to have modified and new objects included in query comparisons without requiring them to first be written to the database.
    Doug

  • Stumped with registering objects

    I have tried mightily, but am not getting behaviour I desire.
    I would like to eventually move to using DTO's to move data in and out of my session tier, but for the short term, I am trying to get the 'quick and dirty' approach to work.
    For instance,
    I query say 40 objects. I store a list of them in session scope in the servlet container. The gui then will allow a user to make some changes to one of these objects, and then resubmit it to the session tier to be saved.
    The problem seems to be I am not starting a unit of work before the changes start, and making the changes to clones. The servlet code does not know about toplink, it just reads a list of objects, picks an arbitrary one to edit, and then resubmits it.
    I was using deepMergeClone on the object to be saved to allow toplink to get a list of differences, and this seemed to work for most scenarios, but not all. I have heard that the merge api is more for objects which have been disconnected from the session.
    I have attached the methods i have written for load/save. Any feedback would be very much appreciated...espicially if it explains that this interm method will work, acknowledging I will implement a better facade pattern with DTO's in the future. (I really need demo quality soon)
    Here is the load method:
    public static Collection returnQueryResult(String queryBarId) {
              UnitOfWork uow= getSession().acquireUnitOfWork();
              Vector facilities= null;
              try {
                   Vector results=
                        (Vector) getSession().readAllObjects(
                             QueryBarResult.class,
                             new ExpressionBuilder().get("id").equal(queryBarId));
                   facilities= new Vector(results.size());
                   Iterator iter= results.iterator();
                   IdentifiableObject theFacility;
                   while (iter.hasNext()) {
                        theFacility= ((QueryBarResult) iter.next()).getQueriedObject();
                        facilities.add(uow.registerExistingObject(theFacility));
                   } catch (Throwable th) {
                   th.printStackTrace();
              return facilities;
    Here is the save:
         public static Object save(IdentifiableValue obj, String sessionName) {
              try {
                   UnitOfWork uow= getSession(sessionName).acquireUnitOfWork();
                   uow.registerObject(obj);
                   uow.deepMergeClone(obj);
                   uow.commit();               
              } catch (DatabaseException e) {
                   e.printStackTrace();
              return getSession(sessionName).readObject(obj);

    Craig,
    Sorry to hear you are having such difficulty getting your demo going. Have you looked at the session-bean and jsp-Servlet demos that are shipped with TopLink. They may help you get something running quickly.
    I would like to clarify some issues that you have raised.
    1. The instances in the shared cache, those returned from a query against a client session, are in fact the original objects. You need to be careful not to modify these outside the context of a UnitOfWork/TX.
    2. The use of the merge API is typically used when the objects are detached from the session through serialization. This means that you architecture has a serialized link between the web tier and the server tier. This is more often accomplished by wrapping your server logic with a session beans. You will also need to ensure that if the web tier and server/ejb tier are in the same JVM that the app server is not passing the object by reference instead of by value.
    3. If the objects you are changing in the web-tier are not separated by a serialized link such as a session-bean then you must register the objects prior to making any changes to them.
    The code you have shown seems to assume that the web application will be in the same JVM and not have a serialized link between it and the persistence layer. Then to ensure you have a copy of the object you use one UnitOfWork to copy the objects and another to persist the changes. If you were willing to have a slightly more stateful system you could just maintain the UnitOfWork and avoid having to register or merge on the save, just call UnitOfWork.commit().
    To address your specific code without writing a complete novel I would suggest the following:
    Here is the load method:
    public static Collection returnQueryResult(String queryBarId) {
    UnitOfWork uow= getSession().acquireUnitOfWork();
    Vector facilities= null;
    try {
    // Note: reading through the UOW will register results
    Vector facilities = (Vector) uow.readAllObjects(QueryBarResult.class, new ExpressionBuilder().get("id").equal(queryBarId));
    uow.release(); // not going to need it any more
    } catch (Throwable th) {
    th.printStackTrace();
    return facilities;
    Here is the save:
    public static Object save(IdentifiableValue obj, String sessionName) {
    try {
    UnitOfWork uow= getSession(sessionName).acquireUnitOfWork();
    uow.readObject(obj); //ensure its cached and registered
    uow.deepMergeClone(obj);
    uow.commit();
    } catch (DatabaseException e) {
    e.printStackTrace();
    return getSession(sessionName).readObject(obj);
    Although this should work for all cases there will be issues if you attempt to instantiate any indirect relationships on the copies returned from the query method. These objects have been copied through a now inactive UOW. If you require lazy loading after the query I would recommend using a more stateful solution an maintaining the UOW.
    I hope this helps you get your demo going quickly. Please let me know if you run into any further complications.
    Doug

  • Applet registered through object tag doesn't work

    Hi..
    If i register an applet through <OBJECT> tag, the applet doesn't appear, but if registering through <applet> tag, it works.
    what happens?
    is there anybody can tell me why?

    The html <object> codes used are below.
    <OBJECT
    classid = "clsid:CAFEEFAC-0014-0002-0004-ABCDEFFEDCBA"
    codebase = "http://java.sun.com/update/1.4.2/jinstall-1_4_2_04-windows-i586.cab#Version=1,4,2,40"
    WIDTH = 100 HEIGHT = 100 >
    <PARAM NAME = CODE VALUE = "MyApplet.class" >
    <PARAM NAME = "type" VALUE = "application/x-java-applet;jpi-version=1.4.2_04">
    <PARAM NAME = "scriptable" VALUE = "false">
    <PARAM NAME = MAYSCRIPT VALUE = true >
    </OBJECT>
    and the parent html file that contain "<iframe> tag" portion is written as below
    <iframe src=iframe_testApplet.htm name=AppletLoader frameborder="no" height=150 width=150 scrolling="no"></iframe>
    and all the parent html file and the iframed-file and the class file is in the same directory. so i didn't specify the "codebase" attribute above. and moreover, when i put a code that specifies the codebase though, it doesn't still work.
    the code specifying codebase is like this.
    <PARAM NAME = CODEBASE VALUE=".">
    I just want to let know that actually I solved above problem just before with some minor change. but I still want to know why it works at this time because there is not so much difference between before and after.
    the change I did is
    1. I rewrite all html code into jsp code
    2. in the jsp code, I specify the codebase with "<%= request.getContextPath()%>/aPath"
    But as you can see, the code base is the directory that contains all the files, parent html file, iframed file and a classFile, although I changed some minor codes, that cannot make it work if it doesn't work without the minor code-change because eventually it has same context from code viewpoints.
    As of now, I just take it as just a JRE bug. Can anyone let me know why it happens?

  • Class not registered. Looking for object with CLSID:

    Hi,
    I had create a custom project system with the help of https://msdn.microsoft.com/en-us/library/vstudio/cc512961.aspx. And which is working fine that I can create a project with extension of .myproj in the VS Experimental Instance window. But when I go for
    the properties in the created project, (Solution Explorer: Right click on the project folder and select properties) it will show an exception that "Class not registered. Looking for object with CLSID:{00000-00-00-000000}" How can I provide Properties
    window for this project system or can I modify the Properties window for any other default VS project system? Please help me.

    Hi mathikp,
    I don't think you did something wrong while creating the project, but instead it could be the issue of environment, I would suggest you to validate following things:
    1, Try to create another blank app to see if the exception still thrown.
    2, Run with an administrator privilege to check if you can get the project work..
    I would not consider its as a coding issue but try to fix Visual Studio probably helps.
    --James
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • LR4.1 : "Edit-In" "Open as Smart Object with Photoshop..." feature doesn't work with 32bits

    Hi there,
    I am running LR4.1/CS5/ACR6.7 on a Win7 64bits system.
    The feature "Edit-In" > "Open as Smart Object with Photoshop..." does work Ok with raw files (.NEF).
    However, when i do try to use the same feature with 32 bits .TIFF files (which are output of the LR4.1's "Edit-In" > "Merge to HDR Pro in Photoshop..." other feature), nothing does happen (the Photoshop application windows does open but w.o the image that i've just selected).
    I've used search engines and Adobe online help to see if there was any limit preventing the usage of this feature with 32 bits .TIF files but couldn't see such note.
    Thanks for your help !
    Albert

    Thanks Rikk,
    That did work with a DNG file :-)
    I am working with very huge .TIF files (400MB), so i am wondering if size could be the main issue (although my PC has lots of HW resources).
    I will explore the DNG way, a format which seems anyways to be very promising now with LR4.
    In case anyone has an idea why it doesn't work the .TIF files, please shoot !

  • Custom Auth. Object with Profile and role assignment not working

    Hi,
    I have created custom Authorization Object with field ACTVT with allowed values - 01,02, 03. Now test it with custom program using AUTHORITY-CHECK OBJECT 'Z_AUTHORIZ' it is working fine and returning sy-subrc 12. At this point i have not created any role using this Auth Object.
    Now I have created custom role ZPM_**** and assigned above Auth object to it with value ACTVT 03. Assigned this role to user.
    When I try to test the above custom program with any ACTVT value it is giving sy-subrc as 0. Used below custom code in program.
    AUTHORITY-CHECK OBJECT 'Z_AUTHORIZ'
                ID 'ACTVT'  FIELD '01'.
    Am I missing anything? The profiles are generated correctly. 
    Best Regards,
    Nilesh

    Below are the screen shots for PFCG:

  • Java object with ArrayList of custom objects not working

    I have a custom java object that has an ArrayList of another set of custom objects (code listed below). I can pull back a Customer object (to flex client) and it's recognized as a Customer action script object, but the ArrayList in the Customer object is not recognized as an ArrayCollection of Accounts. Instead it is an ArrayCollection of Action Script Objects.
    At first I thought something was wrong with my action script Account class, but then I tried to pull back just an Account and it was recognized as an action script Account. It's just when I have my Customer object with an ArrayList of Accounts that it isn't getting converted.
    Is there something else I need to do to have that ArrayList be recognized as an ArrayCollection of Accounts on the Flex Client side? Is there some way of specifying what type an ArrayCollection is mapped to?
    Thanks in advance for the help!
    public class Customer {
         private String name;
         private String address;
         private ArrayList<Account> accounts;
         public Customer(){
         public String getName(){
              return name;
         public void setName(String str){
              name = str;
         public String getAddress(){
              return address;
         public void setAddress(String str){
              address = str;
         public ArrayList<Account> getAccounts(){
              return accounts;
         public void setAccounts(ArrayList<Account> list){
              accounts = list;
    public class Account {
         private long accountNumber;
         private String type;
         private double balance;
         public Account(){
         public long getName(){
              return accountNumber;
         public void setName(long l){
              accountNumber= l;

    I accidently found how to make this work. I may have missed something while reading about blazeDS reflection, but I thought I'd pass this along anyway.
    What I have is I have an class A. In class A I have an arraycollection of Class B. If I want that arraycollection to return to the server with the correct class, then I need to include Class B in the compiled swf. How I have done that is to create a dummy variable of type B. Importing B will not work you actually need to have a member variable of type B even if you don't need it.
    Example
    import dataobjects.B;
    [RemoteClass(alias="dataobjects.A")]
    public class A {
       private var _b:B; //This is never used, but needed to include B object in swf to be reflected.
       private var_ bList:ArrayCollection = new ArrayCollection();
      public function A(){
      public function set bList(list:ArrayCollection):void{
         _bList = list;
      public function get bList():ArrayCollection{
        return _bList;

  • How to register RMI object with runnign Weblogic Server instance?

    I need to write some RMI objects(non EJB) and register it with the already running weblogic server so that I can access them from a RMI client.
    Can some help me with this?

    So more precisely the way I am doing it is
    I have a remote interface
    package com.myserv.rmi;
    public interface NSPQueryExecutionService extends java.rmi.Remote
    public void getQueryExecutionDelegate();
    I have the Implementation as
    package com.myserv.rmi;
    import java.util.Properties;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    public class NSPQueryExecutionServiceImpl
    implements NSPQueryExecutionService
    public static final void main (String[] arg) {
    try {
    Properties properties = null;
    properties = new Properties();
    properties.put (Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    Context context = new InitialContext(properties);
    context.bind("QueryExecutionService", new NSPQueryExecutionServiceImpl());
    System.out.println("================================> QueryExecutionService Bound");
    } catch (Exception ex){
    ex.printStackTrace();
    System.out.println("Unable to start QueryExecutionService");
    public NSPQueryExecutionServiceImpl()
    public void getQueryExecutionDelegate()
    System.out.println("inside remote");
    I compile these classes and I do a weblogic.rmic as
    java weblogic.rmic com.myserv.rmi.NSPQueryExecutionServiceImpl
    I run the NSPQueryExecutionServiceImpl class to bind the RMIObject with the weblogic server.
    Finally when I try to access this from my client it is able to access the object but when I invoke an operation on it gives the exception that RJVM is already shutdown.
    Edited by kuldeep.sharma at 02/15/2007 9:37 AM

  • Multi-page units of work with automatic state management

    Hi Jhs team:
    When my applications need to support an end-user task requiring data entry on many different web pages to complete,
    how to building multi-page units of work with automatic state management ? please give some instruction .

    Ting Rung,
    You can do this in two ways:
    - use a Struts form bean to collect all the values over the requests
    - submit the changes of each request to bc4j, but do not post and commit the changes to the database.
    The latter is easiest. For this to work, you must set the doCommit property of all your save actions in the stuts-condig to false, except for the last save action in the chain of requests.
    In addition, in your application module class, you need to overwrite method postChanges as follows:
    * DO NOT post the changes to the database
    public void postChanges() throws Exception
    // do not post here
    // posting will happen when the commitChanges
    // method on the handler is invoked
    Steven Davelaar,
    Jheadstart Team.

  • Help with Registering objects/access cache

    Below is the save routine i use to persist my top-level objects to the database.
    It seems very likely that I am doing something fundamentally wrong as I am obvserving behaviour that I do not expect.
    For example, I am using a field called version_id to hold an integer for optimistic locking. The first time I save the object, the correct sql is created, and the database row looks as I would expect. However, subsequent attempts to save do not work because I cannot figure out how to get a reference to the object with the incremented version_id.
    It would be much appreciated if someone can see things i am doing incorrecty with the implementation i have included below.
    thanks in advance.
    craig
    public static Object save(IdentifiableValue obj, String sessionName) {
              Object entity= null;
              try {
                   UnitOfWork uow= getSession(sessionName).acquireUnitOfWork();
                   if (obj.isNew())
                        uow.registerObject(obj);
                   entity= uow.deepMergeClone(obj);
                   //                    uow.printRegisteredObjects();
                   uow.commit();
                   //               uow.registerObject(facility);
              } catch (DatabaseException e) {
                   e.printStackTrace();
              Object returnValue= getSession(sessionName).readObject(obj);
              return returnValue;
         }

    When I create a new record, the id (sequence generated) gets set fine, but not the version number.
    When I save a record, the version id is not incremented.
    It seems to use the version number field properly in the sql though.
    Below is my sessions.xml entry, which looks like I am not JTS unless I am doing something incorrect.
    Any help is much appreciated.
    <session>
              <name>default</name>
              <project-xml>toplink.xml</project-xml>
              <session-type>
                   <server-session/>
              </session-type>
              <enable-logging>true</enable-logging>
              <logging-options>
                   <log-debug>true</log-debug>
                   <log-exceptions>true</log-exceptions>
                   <log-exception-stacktrace>true</log-exception-stacktrace>
                   <print-thread>true</print-thread>
                   <print-session>true</print-session>
                   <print-connection>true</print-connection>
                   <print-date>true</print-date>
              </logging-options>
              <login>
              <platform-class>oracle.toplink.internal.databaseaccess.OraclePlatform</platform-class>
                   <datasource>jdbc/toplinkDS</datasource>
                   <uses-external-connection-pool>true</uses-external-connection-pool>
                   <uses-external-transaction-controller>false</uses-external-transaction-controller>
              </login>
         </session>

  • Ipad 2 upgraded to iOS 8.0.2 and the cellular signal doesn't work. Have to restart the unit to work with cellular signal. After a while it goes off and no service indication appears.

    Ipad 2 upgraded to iOS 8.0.2 and the cellular signal doesn't work. Have to restart the unit to work with cellular signal. After a while it goes off and no service indication appears.

    iPad 2, Since upgrading to iOS 8.0.2  the cellular signal indicates I do not have a SIM card. Monday spent hours on the phone with Apple support, backed up my iPad, reset all settings, reloaded my iPad and it still tells me I don't have a SIM card. Tuesday went to AT&T and got a new SIM card on the advice of apple support. It worked perfect until this morning and the NO SIM CARD notice reappeared. Never ever had any problem until the upgrade. I find it inexcusable that Apple refuses to address the issues they caused, iOS 8.0.2 is the Ebola of iPad 2 world. I dont have any cellular service after wasting two days trying to address and fix a problem Apple is responsible for. It's obvious Steve Jobs is no longer running the company. Furious & fustrated. How does Apple expect anyone who uses an iPad 2 for work, to remain a customer who will return to their products?

Maybe you are looking for

  • Problem in Duplex Printing

    Hi, After following the discussion given in the below mentioned threads 1) issue 2) issue I am able to print in duplex mode but still there is problem with the number of pages being printed. Actually I just have to print two pages (back to back on a

  • IMacs and AVCHD nex 5

    Hello, i am very new to the world of the mac, having always used a pc and have a long way to go before i learn how to use it properly. one of the reasons for the switch from pc to mac was a new camera i had bought and wanted to learn to use properly,

  • Please wait  while the document is being processed

    warning...newbie question.... We are using the crystal report viewer on an ASP.NET application. on the parameter panel there is an edit icon, if the user double clicks this,  the report viewer triggers the page to re-load,  then it displays a tiny di

  • Temporary signature for Nokia phones?

    Hi I am looking for a way of signing a midlet with a temporary signature for development purposes for a Nokia phone. I know that in the Motorola iden SDK there is a function which signs the midlet with a signature that lasts 48 hours and works even o

  • AU Instrument  Plugin Question

    I was just curious on how to add more AU Instrument plugin's into LE8.... I have found free one's online, but just wondering how i can shove them into the software program and use them? thank you http://www.myspace.com/sibeatz07