This one time, at band camp, Neil Aggarwal said:
NA>Hello:
NA>
NA>I am using Castor 0.9.4.1 on RedHat Linux 8.0 running Apache 2.0.43, Tomcat
NA>4.0.6, and MySql 3.23.53a.
NA>
NA>Here is a simple test case:
NA>
NA>package test;
NA>
NA>import java.io.*;
NA>import java.net.*;
NA>import javax.servlet.*;
NA>import javax.servlet.http.*;
NA>import org.exolab.castor.jdo.*;
NA>import persistent.*;
NA>
NA>public class LongTransaction extends HttpServlet {
NA> protected void doGet(HttpServletRequest request, HttpServletResponse
NA>response)
NA> throws IOException {
NA> response.setContentType("text/html");
NA> PrintWriter out = response.getWriter();
NA>
NA> try {
NA> // Load the database
NA> JDO jdo = new JDO();
NA> jdo.setDatabaseName("castorTest");
NA> ClassLoader loader = getClass().getClassLoader();
NA> jdo.loadConfiguration(loader.getResource("database.xml").toString());
NA> out.println("<P>Loaded the database");
NA>
NA> // Create a parameters object if we need to
NA> Database db = jdo.getDatabase();
NA> db.begin();
NA> OQLQuery query = db.getOQLQuery("SELECT p from persistent.Parameters
NA>p");
NA> QueryResults results = query.execute();
NA> if( results.size() <= 0 ) {
NA> Parameters parameters = new Parameters();
NA> db.create(parameters);
NA> db.commit();
NA> out.println( "<P>Created a new parameters object");
NA> } else {
NA> db.rollback();
NA> out.println( "<P>There is already a parameters object in the
NA>database");
NA> }
NA> db.close();
NA>
NA> // Load the parameters object from the database
NA> Parameters parameters = null;
NA> db = jdo.getDatabase();
NA> db.begin();
NA> query = db.getOQLQuery("SELECT p from persistent.Parameters p");
NA> results = query.execute();
NA> if( results.hasMore() )
NA> parameters = (Parameters)results.next();
NA> db.rollback();
NA> db.close();
NA> out.println( "<P>Read parameters object from the database" );
NA>
NA> // Update the parameters object
NA> db = jdo.getDatabase();
NA> db.begin();
NA> parameters.setChargePPV(true);
NA> db.update(parameters);
NA> db.commit();
NA> db.close();
NA> out.println( "<P>Updated parameters object" );
NA>
NA> } catch( Exception e ) {
NA> out.println( "<P>Caught exception: "+e );
NA> out.println( "<PRE>" );
NA> e.printStackTrace(out);
NA> out.println( "</PRE>" );
NA> }
NA>
NA> out.close();
NA> }
NA>}
NA>
NA>When I execute the servlet, I get this output:
NA>
NA>Loaded the database
NA>
NA>There is already a parameters object in the database
NA>
NA>Read parameters object from the database
NA>
NA>Caught exception: org.exolab.castor.jdo.ObjectModifiedException: Timestamp
NA>mismatched!
NA>
NA>org.exolab.castor.jdo.ObjectModifiedException: Timestamp mismatched!
NA> at org.exolab.castor.persist.ClassMolder.update(Unknown Source)
NA> at org.exolab.castor.persist.LockEngine.update(Unknown Source)
NA> at org.exolab.castor.persist.TransactionContext.markUpdate(Unknown
NA>Source)
NA> at org.exolab.castor.persist.TransactionContext.update(Unknown Source)
NA> at org.exolab.castor.jdo.engine.DatabaseImpl.update(Unknown Source)
NA> at test.LongTransaction.doGet(LongTransaction.java:56)
NA>
NA>This occurs on the call to db.update().
NA>
NA>Here is my mapping file:
NA><?xml version="1.0"?>
NA>
NA><!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
NA> "http://castor.exolab.org/mapping.dtd">
NA>
NA><mapping>
NA> <class name="persistent.Parameters"
NA> identity="id"
NA> access="shared"
NA> key-generator="MAX"
NA> auto-complete="false">
NA> <map-to table="Parameters" />
NA> <cache-type type="count-limited" />
NA>
NA> <field name="chargePPV"
NA> type="boolean"
NA> get-method="getChargePPV"
NA> set-method="setChargePPV">
NA> <sql name="chargePPV"
NA> type="bit" />
NA> </field>
NA>
NA> <field name="id"
NA> type="integer"
NA> get-method="getId"
NA> set-method="setId">
NA> <sql name="id"
NA> type="integer" />
NA> </field>
NA>
NA> </class>
NA></mapping>
NA>
NA>Here is the persistent.Parameters class:
NA>package persistent;
NA>
NA>import org.exolab.castor.jdo.*;
NA>
NA>public class Parameters implements TimeStampable {
NA> private int id;
NA> private boolean chargePPV = false;
NA> private long timeStamp;
NA>
NA> public int getId() {
NA> return id;
NA> }
NA> public void setId(int id) {
NA> this.id = id;
NA> }
NA>
NA> public boolean getChargePPV() {
NA> return chargePPV;
NA> }
NA> public void setChargePPV(boolean chargePPV) {
NA> this.chargePPV = chargePPV;
NA> }
NA>
NA> public long jdoGetTimeStamp() {
NA> return timeStamp;
NA> }
NA>
NA> public void jdoSetTimeStamp(long timeStamp) {
NA> this.timeStamp = timeStamp;
NA> }
NA>}
NA>
NA>I am using mysql for the back-end. This is the sql script
NA>I used to create the database table:
NA>DROP TABLE IF EXISTS Parameters;
NA>CREATE TABLE Parameters (
NA> id int PRIMARY KEY,
NA> chargePPV bool
NA>) TYPE = InnoDB;
NA>
NA>I submitted this as bug 1107 back in november but no progress has been
NA>made on it according to bugzilla.
Neil,
I just commented on this in the bug report. Please see my comments here:
http://bugzilla.exolab.org/show_bug.cgi?id=1107
Bruce
--
perl -e 'print unpack("u30","<0G)U8V4\@4VYY9&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev