I'm pretty new to OJB, and experiencing something I didn't expect. In
my system, Articles have an associated Group (1:1), Author (1:1),
Category (1:1). My unit test looks like this:
----------------
public void testInsertArticle() {
Article a = new Article();
a.setAuthorId(1);
a.setCategoryId(1);
a.setGroupId(1);
a.setName("This is a test post.");
a.setDescription("This is a description of a test post.");
a.setBody("This is the body of the post. It's got lots of juicy
info.");
a.setActive(true);
try {
broker.beginTransaction();
broker.store(a);
broker.commitTransaction();
} catch (Throwable e) {
e.printStackTrace();
broker.abortTransaction();
fail();
} finally {
broker.close();
// broker.clearCache();
a = null;
}
}
public void testSelectArticles() {
criteria = new Criteria();
criteria.addEqualTo("name", "This is a test post.");
query = new QueryByCriteria(Article.class, criteria);
broker.beginTransaction();
Article a = (Article) broker.getObjectByQuery(query);
assertNotNull(a);
User author = a.getAuthor();
assertNotNull(author);
Group g = a.getGroup();
assertNotNull(g);
broker.commitTransaction();
broker.close();
}
----------------
If I don't clear the cache (notice the commented out line), the second
test fails because (I assume) the cache is handing back the object from
the first test, which doesn't have the group or author objects
assigned. Clearing the cache works correctly. Is this the intended
behavior? Should I have to clear the cache after each insert to force
OJB to fetch the object again?
--Scott
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>