Bruce:
Here is a simple test case I came up with:
package test;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.exolab.castor.jdo.*;
import persistent.*;
public class LongTransaction extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try {
// Load the database
JDO jdo = new JDO();
jdo.setDatabaseName("castorTest");
ClassLoader loader = getClass().getClassLoader();
jdo.loadConfiguration(loader.getResource("database.xml").toString());
out.println("<P>Loaded the database");
// Create a parameters object if we need to
Database db = jdo.getDatabase();
db.begin();
OQLQuery query = db.getOQLQuery("SELECT p from persistent.Parameters
p");
QueryResults results = query.execute();
if( results.size() <= 0 ) {
Parameters parameters = new Parameters();
db.create(parameters);
db.commit();
out.println( "<P>Created a new parameters object");
} else {
db.rollback();
out.println( "<P>There is already a parameters object in the
database");
}
db.close();
// Load the parameters object from the database
Parameters parameters = null;
db = jdo.getDatabase();
db.begin();
query = db.getOQLQuery("SELECT p from persistent.Parameters p");
results = query.execute();
if( results.hasMore() )
parameters = (Parameters)results.next();
db.rollback();
db.close();
out.println( "<P>Read parameters object from the database" );
// Update the parameters object
db = jdo.getDatabase();
db.begin();
parameters.setChargePPV(true);
db.update(parameters);
db.commit();
db.close();
out.println( "<P>Updated parameters object" );
} catch( Exception e ) {
out.println( "<P>Caught exception: "+e );
out.println( "<PRE>" );
e.printStackTrace(out);
out.println( "</PRE>" );
}
out.close();
}
}
When I execute the servlet, I get this output:
Loaded the database
There is already a parameters object in the database
Read parameters object from the database
Caught exception: org.exolab.castor.jdo.ObjectModifiedException: Timestamp
mismatched!
org.exolab.castor.jdo.ObjectModifiedException: Timestamp mismatched!
at org.exolab.castor.persist.ClassMolder.update(Unknown Source)
at org.exolab.castor.persist.LockEngine.update(Unknown Source)
at org.exolab.castor.persist.TransactionContext.markUpdate(Unknown Source)
at org.exolab.castor.persist.TransactionContext.update(Unknown Source)
at org.exolab.castor.jdo.engine.DatabaseImpl.update(Unknown Source)
at test.LongTransaction.doGet(LongTransaction.java:56)
This occurs on the call to db.update().
You can see for yourself at this url:
http://dsl.JAMMConsulting.com/castorTest/servlet/test.LongTransaction
Here is my mapping file:
<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
"http://castor.exolab.org/mapping.dtd">
<mapping>
<class name="persistent.Parameters"
identity="id"
access="shared"
key-generator="MAX"
auto-complete="false">
<map-to table="Parameters" />
<cache-type type="count-limited" />
<field name="chargePPV"
type="boolean"
get-method="getChargePPV"
set-method="setChargePPV">
<sql name="chargePPV"
type="bit" />
</field>
<field name="id"
type="integer"
get-method="getId"
set-method="setId">
<sql name="id"
type="integer" />
</field>
</class>
</mapping>
Here is the persistent.Parameters class:
package persistent;
import org.exolab.castor.jdo.*;
public class Parameters implements TimeStampable {
private int id;
private boolean chargePPV = false;
private long timeStamp;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public boolean getChargePPV() {
return chargePPV;
}
public void setChargePPV(boolean chargePPV) {
this.chargePPV = chargePPV;
}
public long jdoGetTimeStamp() {
return timeStamp;
}
public void jdoSetTimeStamp(long timeStamp) {
this.timeStamp = timeStamp;
}
}
I am using mysql for the back-end. This is the sql script
I used to create the database table:
DROP TABLE IF EXISTS Parameters;
CREATE TABLE Parameters (
id int PRIMARY KEY,
chargePPV bool
) TYPE = InnoDB;
Is there anything else you need to know?
Any suggestions?
Thanks,
Neil.
--
Neil Aggarwal
JAMM Consulting, Inc. (972) 612-6056, http://www.JAMMConsulting.com
Custom Internet Development Websites, Ecommerce, Java, databases
> Without more detail it's tough to say what it is. But what I can suggest
> is that fields of type date, float and double can sometimes fail Castor's
> dirty check (which utilizes a .equals()). This can sometimes be narrowed
> down by employing the dirty="ignore" attribute in the <sql> element of
> the mapping descriptor. Oftentimes by going through this other problems
> may be found getting closer to a solution.
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev