Ilya
I haven't used the ODMG API but from what little I do know from your example
below you have:
Transaction tx = null;
// 3. open transaction
tx = odmg.newTransaction();
tx.begin();
// 4. acquire write lock on new object
tx.lock(employee, Transaction.WRITE);
// 5. commit transaction
tx.commit();
But this does not seem to be doing the insert anywhere (it just seems to do
a lock). I pulled the following from the OneToManyTest.java in the tests
with OJB and found the following sequence of what appears to be an
insertion:
Transaction tx = odmg.newTransaction();
tx.begin();
db.makePersistent(myZoo);
tx.commit();
You appear to be missing the db.makePersistent part which is a seperate
operation from locking.
Hope this helps.
Cheers,
Tim
--------------------------------------------
Tim Gibbs
RBC Capital Markets
Phone: (416) 842-4663
E-Mail: [EMAIL PROTECTED]
-----Original Message-----
From: Ilya Scharrenbroich [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 07, 2003 1:35 PM
To: OJB Users List
Subject: Insertion problems
Hi, Im having a problem inserting objects (version="0.9.8"). I can select
objects from the DB if I insert them beforehand. Also I got tutorial2 to run
with MSSQL fine, inserting, updating etc. I'm not getting any exceptions or
stack traces when I execute the code below.
Thanks,
Ilya
public class Test {
Implementation odmg;
public static void main( String[] args ){
Test test = null;
try{
Implementation odmg = OJB.getInstance();
Database db = odmg.newDatabase();
db.open("repository.xml", Database.OPEN_READ_WRITE);
test = new Test(odmg);
}catch(Exception e){
e.printStackTrace();
System.exit(1);
}
test.insertNewEmployee("Ilya S");
test.listAllEmployees();
}
public Test( Implementation impl ){
this.odmg = impl;
}
public void insertNewEmployee( String name ){
System.out.println("inserting new employee");
// 1. this will be our new object
Employee employee = new Employee();
// 2. now read in all relevant information and fill the new object:
employee.setName(name);
// now perform persistence operations
Transaction tx = null;
// 3. open transaction
tx = odmg.newTransaction();
tx.begin();
// 4. acquire write lock on new object
tx.lock(employee, Transaction.WRITE);
// 5. commit transaction
tx.commit();
}
public void listAllEmployees(){
System.out.println("The list of available products:");
try
{
// 1. open a transaction
Transaction tx = odmg.newTransaction();
tx.begin();
// 2. get an OQLQuery object from the ODMG facade
OQLQuery query = odmg.newOQLQuery();
// 3. set the OQL select statement
query.create("select allEmployees from " +
Employee.class.getName());
// 4. perform the query and store the result in a persistent
Collection
DList allProducts = (DList) query.execute();
tx.commit();
// 5. now iterate over the result to print each product
java.util.Iterator iter = allProducts.iterator();
while (iter.hasNext())
{
System.out.println(iter.next());
}
}
catch (Throwable t)
{
t.printStackTrace();
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
<font face="Times New Roman" size="3">
<p>------------------------------------------------------------------------------</p>
<p> This e-mail may be privileged and/or confidential, and the sender does not waive
any related rights and obligations. Any distribution, use or copying of this e-mail or
the information it contains by other than an intended recipient is unauthorized. If
you received this e-mail in error, please advise me (by return e-mail or otherwise)
immediately.</p>
<p> Ce courriel est confidentiel et prot�g�. L'exp�diteur ne renonce pas aux droits et
obligations qui s'y rapportent. Toute diffusion, utilisation ou copie de ce message ou
des renseignements qu'il contient par une personne autre que le (les) destinataire(s)
d�sign�(s) est interdite. Si vous recevez ce courriel par erreur, veuillez m'en aviser
imm�diatement, par retour de courriel ou par un autre moyen.</p>
<p>====================================================</p>
</font>