Werner, thanks for your replay.

Basically it�s a simple long transaction update.

The code has some abstract classes but I will try to send you some thing
to work with. 

Basically, all the ObjectModifiedException problems I�m having are for
the same reason, Castor does the dirty checking and gets different or
wrong values. Is there a way to debug step by step what�s going on
inside Castor to check the values it gets when it does the dirty
checking? That will help to solve a lot of problems. 

Thanks a lot and best regards.





MySql Server 4.0.13-nt
castor-0.9.5.3.jar
mysql-connector-java-3.0.9-stable-bin.jar
jdbc-se2.0.jar






-----------------------------------------------------------------
package com.costes.db.castor;

import org.exolab.castor.jdo.JDO;
import org.exolab.castor.jdo.Database;
import org.exolab.castor.jdo.PersistenceException;
import org.exolab.castor.jdo.DatabaseNotFoundException;
import org.exolab.castor.util.Logger;

import java.io.PrintWriter;

import com.costes.config.Configuration;

public class CastorHelper
{
    private static JDO jdo;

    synchronized static public Database getDatabase() throws
PersistenceException, DatabaseNotFoundException
    {
        {
            if (jdo == null)
            {
                PrintWriter writer = null;
                jdo = new JDO(Configuration.DB_NAME);
                if(Configuration.DEBUG)
                {
                    writer = new Logger(System.out).setPrefix("Costes");
                    jdo.setLogWriter(writer);
                }
                jdo.setConfiguration(new
CastorHelper().getClass().getResource(Configuration.DB_FILE).toString())
;
            }

            Database db = null;
            db = jdo.getDatabase();
            return db;
        }
    }
}
-----------------------------------------------------------------


package com.costes.db.castor;

import org.exolab.castor.jdo.*;
import com.costes.config.Configuration;

/**
 * User: Gonzalo Abollado
 * Date: 05-ene-2004
 */
public abstract class AbsCastorBaseObject implements TimeStampable
{
    public static final String ID           = "id";

    public static final int STATE_NEW           = 1;
    public static final int STATE_MODIFY        = 2;
    public static final int STATE_QUERY         = 3;
    public static final int STATE_DELETE        = 4;

    private int iState = STATE_QUERY;
    private long timestamp;

    private Integer id;

    public AbsCastorBaseObject()
    {
    }

    protected void setState(int _iState)
    {
        iState = _iState;
    }

    public int getState()
    {
        return iState;
    }

    public void setToDelete()
    {
        setState(STATE_DELETE);
    }

    public void setToUpdate()
    {
        if(iState == STATE_QUERY)
        setState(STATE_MODIFY);
    }

    public void update() throws PersistenceException
    {
        Database database = null;

        try
        {
            database = CastorHelper.getDatabase();
            database.begin();
            update(database);
            database.commit();
        }
        catch(PersistenceException e)
        {
            System.out.println(e.getMessage());
            e.printStackTrace();
            throw e;
        }
        finally
        {
            try
            {
                if(database != null && !database.isClosed())
                {
                    if(database.isActive())
                        database.rollback();
                    database.close();
                    database = null;
                }
            }
            catch (PersistenceException e)
            {
                e.printStackTrace();
            }
        }
    }

    public void update(Database _database) throws PersistenceException
        {
        if(getId() == null && iState != STATE_DELETE)
            iState = STATE_NEW;

                if(iState == STATE_NEW)
                {
                        insertRecord(_database);
                        //setState(STATE_MODIFY);
                }
                else if(iState == STATE_MODIFY)
                        modifyRecord(_database);
                else if(iState == STATE_DELETE)
                        deleteRecord(_database);

        iState = STATE_QUERY;
        }

    protected void insertRecord(Database _database) throws
PersistenceException
    {
        _database.create(this);
    }

    protected void modifyRecord(Database _database) throws
PersistenceException
    {
        _database.update(this);
    }

    protected void deleteRecord(Database _database) throws
PersistenceException
    {
        if(getId() != null)
        {
            if(Configuration.DEBUG)
                System.out.println("Borrando: " + this);
            _database.update(this);
            _database.remove(this);
        }
    }


    public static AbsCastorBaseObject load(Class _class, Integer _id,
Database _database) throws PersistenceException
    {
        AbsCastorBaseObject baseObject  = null;
        baseObject  = (AbsCastorBaseObject)_database.load(_class, _id);
        baseObject.setState(STATE_QUERY);

        return baseObject;
    }

    public static AbsCastorBaseObject load(Class _class, Integer _id)
throws PersistenceException
    {
        AbsCastorBaseObject baseObject  = null;
        Database            database    = null;
        try
        {
            database    = CastorHelper.getDatabase();
            database.begin();
            baseObject  = (AbsCastorBaseObject)database.load(_class,
_id, Database.ReadOnly);
            database.commit();
            baseObject.setState(STATE_QUERY);
        }
        finally
        {
            try
            {
                if(database != null && !database.isClosed())
                {
                    if(database.isActive())
                        database.rollback();
                    database.close();
                }
            }
            catch (PersistenceException e)
            {
                e.printStackTrace();
            }
        }

        return baseObject;
    }

    public long jdoGetTimeStamp()
    {
        return timestamp;
    }

    public void jdoSetTimeStamp(long arg0)
    {
        this.timestamp = arg0;
    }

    public Integer getId()
    {
        return id;
    }

    public void setId(Integer _id)
    {
        id = _id;
    }

    public boolean canBeDeleted() throws PersistenceException
    {
        return false;
    }

    public boolean equals(Object _object)
    {
        AbsCastorBaseObject baseObject = null;
        baseObject = (AbsCastorBaseObject) _object;

        if(_object == null)
            return false;

        if(baseObject.getId() == null && this.getId() == null)
            return super.equals(_object);

        if(baseObject.getId() == null && this.getId() != null)
            return false;

        if(this.getId() == null && baseObject.getId() != null)
            return false;


        try
        {
            if(this.getId().compareTo(baseObject.getId()) == 0)
                return true;
        }
        catch(Exception e)
        {
            e.printStackTrace();
            return false;
        }

        return false;
    }
}

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


package com.costes.config;

/**
 * User: Gonzalo Abollado
 * Date: 06-ene-2004
 */
public class Configuration
{
    public static final boolean DEBUG   = false;
    //public static final boolean DEBUG   = true;
    public static final String DB_NAME      = "mydb";

    public static final String DB_FILE      = "/database.xml";
    public static final String IDIOMA_FILE  = "/idiomas.xml";
    public static final String TEXTOS_FILE  = "/textos.xml";
}


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

package com.costes.base;

import com.costes.db.castor.AbsCastorBaseObject;
import org.exolab.castor.jdo.PersistenceException;

/**
 * User: I�aky
 * Date: Dec 25, 2003
 */

public class Factura extends AbsCastorBaseObject
{
    public static final String ID_CERTIFICACION     = "idCertificacion";
    public static final String REFERENCIA           = "referencia";
    public static final String DATO_CONTABLE_1      = "datoContable1";
    public static final String DATO_CONTABLE_2      = "datoContable1";
    public static final String DATO_CONTABLE_3      = "datoContable1";
    public static final String IMPORTE              = "importe";

        private Integer idCertificacion;
        private String referencia;
        private String datoContable1;
        private String datoContable2;
        private String datoContable3;
    private double  importe;

        public Integer getIdCertificacion()
        {
                return idCertificacion;
        }

        public void setIdCertificacion(Integer _idCertificacion)
        {
                idCertificacion = _idCertificacion;
        }

        public String getReferencia()
        {
                return referencia;
        }

        public void setReferencia(String _referencia)
        {
                referencia = _referencia;
        }

        public String getDatoContable1()
        {
                return datoContable1;
        }

        public void setDatoContable1(String _datoContable1)
        {
                datoContable1 = _datoContable1;
        }

        public String getDatoContable2()
        {
                return datoContable2;
        }

        public void setDatoContable2(String _datoContable2)
        {
                datoContable2 = _datoContable2;
        }

        public String getDatoContable3()
        {
                return datoContable3;
        }

        public void setDatoContable3(String _datoContable3)
        {
                datoContable3 = _datoContable3;
        }

    public double getImporte()
    {
        return importe;
    }

    public void setImporte(double _importe)
    {
        importe = _importe;
    }

    public String toString()
    {
        StringBuffer sbText = null;

        sbText = new StringBuffer();

        sbText.append("\n\tID: ")
            .append(getId())
            .append(", Certificacion: ")
            .append(idCertificacion)
            .append(", Referencia: ")
            .append(referencia)
            .append(", DatoContable1: ")
            .append(datoContable1)
            .append(", DatoContable2: ")
            .append(datoContable2)
            .append(", DatoContable3: ")
            .append(datoContable3);

        return sbText.toString();
    }

    public static Factura load(Integer _id) throws PersistenceException
    {
        return (Factura)AbsCastorBaseObject.load(Factura.class, _id);
    }

}

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

package com.costes.test;

import com.costes.base.Factura;


import org.exolab.castor.jdo.PersistenceException;

/**
 * User: Gonzalo Abollado
 * Date: 26-ene-2004
 */
public class TestPadre
{
    public static void main(String[] arg)
    {
        Factura factura = null;

        try
        {
            factura = Factura.load(new Integer(483));

            factura.setToUpdate();
            factura.update();
        }
        catch (PersistenceException e)
        {
            e.printStackTrace();
        }
    }


}
-----------------------------------------------------------------



-----Original Message-----
From: Werner Guttmann [mailto:[EMAIL PROTECTED] 
Sent: lunes, 12 de abril de 2004 20:30
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] ObjectModifiedException using double in MySql
with out size.


Gonzalo,

can you please post a code fragment, a mapping file, et alias so that I
can simulate your findings ? Parta from this, what version of mySQL are
you using, 
and what's the release number of the JDBC driver for mySQL ? 

Regards
Werner

On Mon, 12 Apr 2004 17:15:51 +0200, Gonzalo Abollado wrote:

>
>Hello,
>
>I�m run into another ObjectModifiedException problem. In this case I
was
>using a double field in MySQL with out specifying the size of the
field.
>
>In some situations, I can�t really tell when, but maybe it has to do
>with values like: 123123,93 maybe a rounding problem, I�m not sure...
>The thing is that using the same value that fails using double with out
>specifying the size, specifying a size of 10,2 in the double field it
>works fine.
>
>Regards,
>Gonzalo Abollado.
>
>----------------------------------------------------------- 
>If you wish to unsubscribe from this mailing, send mail to
>[EMAIL PROTECTED] with a subject of:
>        unsubscribe castor-dev
>

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to