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]>