Mahler Thomas wrote:
Hi,I've been debugging my simple test application, and I've seen some things I would like to know:
You have to look at the state implementations in org.apache.ojb.odmg.states
to get an idea of the semantics of each of them.
StateOldClean.commit() is implemented as follows:
/**
* commit the associated transaction
*/
public void commit(ObjectEnvelope mod, PersistenceBroker broker)
{
}
as you can see, there is no persistence operation, as an old clean object is
regarded as being in sync with the db. OJB won't perform an insert or update
here!
cheers,
Thomas
- Marking as dirty a StateNewDelete object changes to StateNewDirty. I don't know if this is the correct transition (should I read the ODMG book to know that?).
- The commit() method of ObjectEnvelopeTable marks any modified object as dirty:
ObjectEnvelopeTable.java (snippet starts in line 165)
...
if (mod.hasChanged())
{
// implicitely acquire a write lock !
transaction.lock(mod.getObject(), Transaction.UPGRADE);
// mark object dirty
mod.setModificationState(mod.getModificationState().markDirty());
}
...
So the object that is in StateNewDelete changes to StateNewDirty and it is finally saved in the database.
This is a part of the log I get:
[org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: SQL: SELECT NAME,ID_A,ID FROM B WHERE ID = ?
[DEFAULT] DEBUG: transition: prueba_ojb.B{100} (org.apache.ojb.odmg.states.StateNewDirty --> org.apache.ojb.odmg.states.StateNewDelete)
[DEFAULT] DEBUG: transition: prueba_ojb.B{100} (org.apache.ojb.odmg.states.StateNewDelete --> org.apache.ojb.odmg.states.StateNewDirty)
[org.apache.ojb.broker.accesslayer.JdbcAccess] DEBUG: executeInsert : B(100) = {NAME = PROBANDO, ID_A = 1}
[org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: SQL: INSERT INTO B (ID,NAME,ID_A) VALUES ( ?, ?, ? )
[DEFAULT] DEBUG: transition: prueba_ojb.B{100} (org.apache.ojb.odmg.states.StateNewDirty --> org.apache.ojb.odmg.states.StateOldClean)
Thank you in advance.
-----Urspr�ngliche Nachricht-----<mailto:ojb-user-unsubscribe@;jakarta.apache.org>
Von: Jose Maria Lopez Lagunas [mailto:chema@;visual-limes.com]
Gesendet: Mittwoch, 13. November 2002 10:26
An: OJB Users List
Betreff: ODMG States problem
Hi.
I'm having a problem with the following code:
...
Transaction tx = null;
try {
tx = ojb.newTransaction();
tx.begin();
A a = getA(1); // Retrieves the object from the DB using a OQL query
B b = new B();
b.setId(100);
db.makePersistent(b);
b.setName("PROBANDO");
b.setId_a(a.getId());
a.getLista().add(b);
db.deletePersistent(b);
a.getLista().remove(b);
tx.commit();
}
catch (Exception ex) {
tx.abort();
}
...
The mapping is:
<class-descriptor class="prueba_ojb.A" table="A">
<field-descriptor id="1" name="id" column="ID" jdbc-type="INTEGER" primarykey="true" />
<field-descriptor id="2" name="name" column="NAME" jdbc-type="VARCHAR" />
<collection-descriptor name="lista" element-class-ref="prueba_ojb.B"
auto-retrieve="true" auto-update="false" auto-delete="false" <!-- as OJB advises to use with ODMG -->
orderby="id">
<inverse-foreignkey field-id-ref="3"/>
</collection-descriptor>
</class-descriptor>
<class-descriptor class="prueba_ojb.B" table="B">
<field-descriptor id="1" name="id" column="ID" jdbc-type="INTEGER" primarykey="true" />
<field-descriptor id="2" name="name" column="NAME" jdbc-type="VARCHAR" />
<field-descriptor id="3" name="id_a" column="ID_A" jdbc-type="INTEGER" />
</class-descriptor>
I suppose OJB should do nothing since I create a new object (class B), make persistent, modify it and finally delete it. But this object makes the following transitions in its state:
StateNewDirty -> StateNewDelete -> StateNewDirty -> StateOldClean
So the object is stored in the database.
I don't know if there is a bug or I don't understand the ODMG part of OJB.
Thank you in advance.
--
To unsubscribe, e-mail:
For additional commands, e-mail: <mailto:ojb-user-help@;jakarta.apache.org>
--
To unsubscribe, e-mail: <mailto:ojb-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:ojb-user-help@;jakarta.apache.org>
-- To unsubscribe, e-mail: <mailto:ojb-user-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:ojb-user-help@;jakarta.apache.org>
