Ciao Danilo,
your solution and OJB works well!
Was another silly newbie question ;-)

Thank you



Danilo Tommasina wrote:

hi,


this means that a ShopTransaction is composed by a ShopTransaction and a Transaction database entries. Because of the flag auto-delete="true" what you are experiencing is absolutely normal.
Also you have 2 entries in different tables for one ShopTransaction instance, deleting the ShopTransaction will remove the entries in the 2 tables.



Is exactly what I want! When is deleted the record with transaction_id = 2041 in table ShopTransaction, the delete action should be propagated to table Transaction, but in my log I've 2 delete: a delete on table ShopTransaction with transaction_id = 2022 and a delete in table Transaction_id=2042


uh, there is nothing wrong about this, you have 2 db entries so so you need 2 DELETE statements, the Transaction has a foreignkey on ShopTransaction's primary key, however there is no constraint that says Transaction.transactionId must be equal to ShopTransaction.transactionId

Now you could just make ShopTransaction.transactionId an anonymous field so that it will not appear in you object model and just use Transaction.transactionId as your object's primary key.



>>> transaction = new ShopTransaction();
>>> transaction.setTransaction_id(transaction_id);
>>> Criteria crit = new Criteria();
>>> crit.addEqualTo("transaction_id", new Integer(transaction_id));
>>> Query query = QueryFactory.newQuery(ShopTransaction.class,crit);


1. you should declare transaction as local method variable and not use a class variable
2. you do not need to generate a query (you don't do anything with it anyways in this piece of code)


when deleting an instance (and the primary key is set) OJB should manage to delete the correct object even if it has not been completely materialised, so you do not need to do any query.



1. I've seen this example in the tutorial. I don't understand how this can make the difference.
2. How can I get and delete a ShopTransaction (and Transaction) with a specified transaction_id without instantiate a new ShopTransaction ?


Thank you


Ok try this code:


Criteria c= new Criteria();
c.addEqualTo( "super.transactionId", new Integer( transactionId ) );

The only correction is c.addEqualTo( "transaction_id", new Integer( transactionId ) );


Query q= new QueryByCriteria( ShopTransaction.class, c );


broker.beginTransaction();
Object obj= broker.getObjectByQuery( q );
if ( obj != null ) {
    broker.delete( obj );
}
broker.commitTransaction();


(I didn't try the code, I hope there is no syntax error)


bye
danilo






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



Reply via email to