I am having trouble with OJB and locking when adding things that have cascading relationships

I am having trouble with OJB and locking when adding things that have cascading relationships

Post by starbuxma » Tue, 11 Nov 2003 21:29:55


Hi all, I am using OJB and I can't seem to add a record to the
database if that object contains another object that is a) mapped in
the mapping and b) not already in the mapping. The error I get is:

OJB works reliably in all the other test suits:
-- adding any object and not imposing any connections, ie, they have
no elements that need to cascade
-- retreiving results (either with a criteria or alll records)

I dont know whats going on and would appreciate som ehelp - thanks in
advance

Josh

Time: 2.674
There was 1 error:
1) testAddProjectWithExistingEmployer(com.joshlong.portfolio.bos.tests.PortfolioTest)com.joshlong.portfolio.PortfolioException:
org.odmg.LockNotGrantedException: Can not lock ID:0Finished:Mon Nov 10
04:02:34 PST 2003
Started:Mon Nov 10 04:02:34 PST 2003
Title:Foo Bar
Employer:
------------------------



public void testAddProjectWithNewEmployer()
throws Exception {
// the pk for the Employer class is id and I didnt
//set it -- I want OJB to add it as well as add the Employer
//which also doesnt have the pk set which I presume makes it
// add it as opposed to updating it ...

Employer employer = new Employer();
employer.setContactInfo("this is the contact info");
employer.setName("le nom - " + new Date());
employer.setDuties("a;b;c;d");

portfolio.addEmployer(employer); // see below fo rthe code
behind addEmployer ( Employer);

Employer e = portfolio.getEmployerByName(name);

Project project = new Project();
project.setEmployer(employer);

project.setDescription("This is a description of the
things.");
project.setFinished(new Date());
project.setStarted(new Date());
project.setName("Joshua Long");
portfolio.addProject(project);
}

addEmployer is basically just a more specific method that in turn
calls:
void addRecord ( Object record )
throws PortfolioException
{
Implementation i = OJB.getInstance();
Database db = i.newDatabase();
db.open("default", Database.OPEN_READ_WRITE);
Transaction txc = i.newTransaction();
txc.begin();
txc.lock(record, Transaction.WRITE);
txc.commit();
db.close() ;
}