Hi Sean,

You are encountering a typical getting started problem with the ODMG API.
You always have to keep in mind that ODMG works a object level transaction manager. It only performs database operations if it Objects are new or if there have been changes *during* the current transaction.


This explains exactly your situation:
The first time OJB/ODMG detects that  the object test is new during
tx.lock(test, Transaction.WRITE);

In the subsequent runs it detects that test is an existing object in the database. As there are no changes to test between the
tx.lock(test, Transaction.WRITE);


and
tx.commit();

nothing happens.

The solution:
call
test.setXXX(...);
to modify the object *during* the transaction.

If you are receiving a changed version of test from GUI
you can call

((TransactionExt) tx).markDirty(test);

This will inform the transaction that the object has been modified outside the transaction and that an UPDATE has to be executed.

cheers,
Thomas

Sean Kleinjung wrote:
Hello,

We are attempting to use the Object-Relational Bridge in a web
application that is being deployed to the Novell eXtend application
server. We seem to have gotten everything installed and configured
correctly, and are working through a simple servlet we wrote based
heavily on the ODMG tutorial.

We have, however, run into a bizarre problem. If we package and deploy
the web application, then call a servlet that is supposed to insert a
new (id,name) tuple into a test table, the operation succeeds. Once. If
we call the servlet multiple times, only the first object gets inserted.
Repeated calls appear to have no effect on the database. No exception or
error condition occurs, and as far as the servlet code can tell the
operation succeeds, but there is no change on the database.

Following is the code in question:

/*
 * SNIP
 */

public class TestServlet extends HttpServlet {
        Implementation odmg = null;

/**
* */
public TestServlet() {
super();
}


/*
* @see javax.servlet.GenericServlet#init()
*/
public void init() throws ServletException {
super.init();

odmg = OJB.getInstance();
Database db = odmg.newDatabase();
try {
db.open( "users", Database.OPEN_READ_WRITE);
} catch (ODMGException ex) {
throw new ServletException(
"Failed to open database: ", ex);
}
}



protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Test test = new Test();
test.setName(req.getParameter("name"));


                Transaction tx = null;
                try {
                        tx = odmg.newTransaction();
                        tx.begin();
                        tx.lock(test, Transaction.WRITE);
                        tx.commit();
                } catch (LockNotGrantedException lnge) {
                        //lnge.printStackTrace();
                        throw new ServletException(lnge);
                }

                resp.getWriter().println("Done.");
        }
}

/*
 * /SNIP
 */

I tried an alternate implementation where the ODMG implementation object
and database objects were created/opened and closed during every
invocation of the servlet's doGet method, but this exhibited the same
effect.

We are stumped on this, and any help would be greatly appreciated.

Thanks for your time,
Sean Kleinjung
Web Application Developer
Agri ImaGIS Technologies, Inc.
http://www.satshot.com

--------------------------------------------------------------------------

For reference, the repository_user.xml file for this application is
included below:

--------------------------------------------------------------------------

<!-- Please keep user defined mappings in this file only
     to avoid mixing user defined and system mappings. -->
<!-- Mapping of User defined classes starts here -->

<!-- The mappings for the tutorial classes are placed here to make it
easier to find them for OJB newbies.
Please remove them if you don't need them in your environment. -->
<!-- mssql database description -->
<jdbc-connection-descriptor
jcd-alias="users"
platform="MsSQLServer"
jdbc-level="2.0"
jndi-datasource-name="java:comp/env/jdbc/UsersDB"/>


<!-- Definitions for com.satshot.test.Test -->
   <class-descriptor
          class="com.satshot.test.Test"
          table="Test"
   >
      <field-descriptor
         name="oid"
         column="oid"
         jdbc-type="INTEGER"
         primarykey="true"
         access="readonly"
      />
      <field-descriptor
         name="name"
         column="name"
         jdbc-type="VARCHAR"
      />
   </class-descriptor>


<!-- Mapping of User defined classes ends here -->



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to