This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 139024

Summary: Commitchanges() does not write data to database
Product: obsolete Reporter: pncblessed <pncblessed>
Component: visualwebAssignee: John Baker <jbaker>
Status: RESOLVED INVALID    
Severity: blocker    
Priority: P3    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description pncblessed 2008-07-04 12:12:30 UTC
Java Server Faces ---> Persistance ---> MYSQL Database

CommitChanges() appears to work but in fact does not write any data to the database or produce any error if you change 
the SQL command to filter data on the CachedDataProvider.

To recreate

1. Create a small MYSQL table - add a few rows - Have an ID field that is autonumbering.
2. Create a Java Enterprise Application
3. Create a Java Server Faces Page and drop a grid on it
4. Drop the database on to the grid
5. Change the fields to be text editing fields instead of static display
6. Create two buttons - add new record and save changes

Add new record 
--------------
        cachedDataProvider1().appendRow();

Save Changes
------------
        
        polinesDataProvider.commitChanges();
        polinesDataProvider.refresh();
        return null;


Run the project, it will work fine you can add rows and change data.

Here's the problem, the real world problem I have is putting in a purchase order where there is header and detail 
information, so you need to change the SQL for the table to filter out anything that is not on "this" purchase order.

In the INIT phase I change the SQL witht he following code:-


                try {
            String sSQL="SELECT ALL polines.id, polines.poid, polines.description, polines.qty, polines.price, 
polines.total  FROM polines WHERE poid=" + cachedRowSetDataProvider1.getValue("id");
            polinesDataProvider.getCachedRowSet().setCommand(sSQL);
            polinesDataProvider.getCachedRowSet().execute();
            polinesDataProvider.refresh();
              } catch (Exception e) {
                  
              }

Now the records will not save, commitChanges appears to work and raises no error, but because I have a WHERE in the 
SQL string it does not write to the dataase.
Comment 1 pncblessed 2008-07-04 12:51:16 UTC
Workaround:-

When you append the row save the changes straight away and it works - in this case...

  polinesDataProvider.setCursorRow(newRow);
        polinesDataProvider.setValue("poid", cachedRowSetDataProvider1.getValue("id"));
        polinesDataProvider.commitChanges();
        polinesDataProvider.refresh();

As you can see here i set a value (which is the purchase order ID of the header) in this case.
Comment 2 John Baker 2008-09-19 04:42:21 UTC
At least from the code provided, if you want to get the value of a field from the data provider,
cachedRowSetDataProvider1.getValue("id");
should be executed in prerender(), not _init().

At _init() cachedRowSetDataProvider1 hasn't been initialized yet

If this analysis is not correct, please attach a zip file of your project.