Re: N same class mapping question...
Hi Brian, I have fixed the OTM bug (M:N relations wasn't updated). Thanks for detailed bug report. Regards, Oleg On Tuesday 14 October 2003 14:16, Brian McCallister wrote: > On Tuesday, October 14, 2003, at 09:33 AM, [EMAIL PROTECTED] wrote: > > Hej Brian, > > > >> -Original Message- > >> From: Brian McCallister [mailto:[EMAIL PROTECTED] > >> > >> I have mixed and matched the value, but it hasn't mattered. I had > >> thought it might care so I tried various combinations. It in > >> this vase > >> being a nebulous entity who thwarts my plans, as to my knowledge > >> neither OJB nor Postgres care about case of table names. > > > > Which API do you use? > > OTM (with OQL and Iterators instead of DLists -- see findById(...) > below ). The project is part of my OTM learning process so I can write > some docs on it. > > > Which concrete class is instantiated > > for the list field? > > Default - I don't specify anything so should be a Vector. > > > Can you post the code that you use > > to persist the objects? > > Of course, I will put a tarball ( > http://kasparov.skife.org/kim-broken.tar.gz (includes jars so is big, 8 > megs)) of the whole project up, the relevent pieces: > > Test Failure: > --- > There was 1 failure: > 1) > testRequestFriend(org.skife.kim.model.TestUserRelations)junit.framework. > AssertionFailedError: expected:<1> but was:<0> > at > org.skife.kim.model.TestUserRelations.testRequestFriend(TestUserRelation > s.java:76) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav > a:39) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor > Impl.java:25) > at > com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java: > 12) > --- > FAILURES!!! > Tests run: 1, Failures: 1, Errors: 0 > > The Test: (one and two are created in the setup and removed in the > teardown) > - > public void testRequestFriend() throws Exception > { > Unit unit = Unit.begin(); > one = UserRepository.findById(one.getId(), unit); > two = UserRepository.findById(two.getId(), unit); > one.addFriend(two); > unit.commit(); > > TestTools.clearCache(); > > unit = Unit.begin(); > one = UserRepository.findById(one.getId(), unit); > List friends = one.getFriends(); > Assert.assertEquals(1, one.getFriends().size()); // This > Assertion Fails > unit.commit(); > } > --- > > Unit simply provides a convenience wrapper around OTMConnections and > Transactions: > -- > package org.skife.kim.infra; > > import org.apache.ojb.otm.core.Transaction; > import org.apache.ojb.otm.OTMConnection; > import org.apache.ojb.otm.kit.SimpleKit; > import org.apache.ojb.broker.PersistenceBrokerFactory; > > /** > * Unit of Work shortened for typing purposes > * > * TODO: Add a factory method that takes a long argument and will > rollback the transaction > * after an elapsed time has passed. Each getConnection() call > extends the time > * by the initial value. This allows for clearing the connection > before the session > * times out in web apps > */ > public class Unit > { > private Transaction transaction; > private OTMConnection connection; > > private Unit() > { > this.connection = > SimpleKit.getInstance().acquireConnection(PersistenceBrokerFactory.getDe > faultKey()); > this.transaction = > SimpleKit.getInstance().getTransaction(this.connection); > } > > public static Unit begin() > { > Unit unit = new Unit(); > unit.transaction.begin(); > return unit; > } > > /** > * @throws org.skife.kim.infra.UnitException if the Unit of Work > has already been committed > * or rolled back - either via this or the > underlying > * Transaction/OTMConnection > */ > public void commit() throws UnitException > { > if (! transaction.isInProgress()) > { > throw new UnitException("Unit of work already closed"); > } > this.transaction.commit(); > this.connection.close(); > } > > /** > * @throws org.skife.kim.infra.UnitException if the Unit of Work > has already been committed > * or rolled back - either via this or the > underlying > * Transaction/OTMConnection > */ > public void rollback() throws UnitException > { > if (! transaction.isInProgress()) > { > throw new UnitException("Unit of work already closed"); > } > this.transaction.rollback(); > this.
Re: N same class mapping question...
Follow up.. Changing the OTM Test to use PB style QueryByCriteria also fails: public void testRequestFriendOTMTwo() throws Exception { OTMConnection conn = SimpleKit.getInstance().acquireConnection(PersistenceBrokerFactory.getDe faultKey()); org.apache.ojb.otm.core.Transaction tx = SimpleKit.getInstance().getTransaction(conn); tx.begin(); Criteria tomCrit = new Criteria(); tomCrit.addEqualTo("id", one.getId()); Query tomQuery = new QueryByCriteria(User.class, tomCrit); Criteria mikeCrit = new Criteria(); mikeCrit.addEqualTo("id", two.getId()); Query mikeQuery = new QueryByCriteria(User.class, mikeCrit); User tom = (User) conn.getIteratorByQuery(tomQuery).next(); User mike = (User) conn.getIteratorByQuery(mikeQuery).next(); tom.addFriend(mike); tx.commit(); conn.close(); PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker(); broker.clearCache(); broker.close(); conn = SimpleKit.getInstance().acquireConnection(PersistenceBrokerFactory.getDe faultKey()); tx = SimpleKit.getInstance().getTransaction(conn); tx.begin(); Criteria timCrit = new Criteria(); timCrit.addEqualTo("id", one.getId()); Query timQuery = new QueryByCriteria(User.class, timCrit); User tim = (User) conn.getIteratorByQuery(timQuery).next(); Assert.assertEquals(1, tim.getFriends().size()); tx.commit(); conn.close(); } -Brian On Tuesday, October 14, 2003, at 11:39 AM, Brian McCallister wrote: On Tuesday, October 14, 2003, at 10:29 AM, [EMAIL PROTECTED] wrote: I bet this is the problem. You'd probably better use one of the managed collections. Could you please check by outputting xxx.getClass().getName() somewhere? On retrieved collections it uses: .org.apache.ojb.broker.util.collections.RemovalAwareCollection F Time: 2.508 If 'one' is a non-manageable collection, such as Vector, then 'one' does not get marked as dirty, so it won't be stored. (Just a guess, maybe someelse can tell you more exactly.) On new objects it is an ArrayList, on retrieved objects a RemovalAwareCollection I tried changing the collection-class to org.apache.ojb.broker.util.collections.ManageableArrayList but have the same results: public void testRequestFriend() throws Exception { Unit unit = Unit.begin(); one = UserRepository.findById(one.getId(), unit); two = UserRepository.findById(two.getId(), unit); System.err.println(one.getFriends().getClass().getName()); one.addFriend(two); unit.commit(); TestTools.clearCache(); unit = Unit.begin(); one = UserRepository.findById(one.getId(), unit); List friends = one.getFriends(); System.err.println(friends.getClass().getName()); Assert.assertEquals(1, one.getFriends().size()); unit.commit(); } - org.apache.ojb.broker.util.collections.ManageableArrayList org.apache.ojb.broker.util.collections.ManageableArrayList F Time: 2.732 There was 1 failure: 1) testRequestFriend(org.skife.kim.model.TestUserRelations)junit.framework .AssertionFailedError: expected:<1> but was:<0> at org.skife.kim.model.TestUserRelations.testRequestFriend(TestUserRelatio ns.java:79) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja va:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso rImpl.java:25) at com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java :12) FAILURES!!! Tests run: 1, Failures: 1, Errors: 0 Hmm Using the PB API to do the same thing... public void testRequestFriendPB() throws Exception { PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker(); Criteria tomCrit = new Criteria(); tomCrit.addEqualTo("id", one.getId()); Query tomQuery = new QueryByCriteria(User.class, tomCrit); User tom = (User) broker.getObjectByQuery(tomQuery); Criteria mikeCrit = new Criteria(); mikeCrit.addEqualTo("id", one.getId()); Query mikeQuery = new QueryByCriteria(User.class, mikeCrit); User mike = (User) broker.getObjectByQuery(mikeQuery); Assert.assertNotNull(tom); Assert.assertNotNull(mike); tom.addFriend(mike); broker.store(tom); broker.clearCache(); User tim = (User) broker.getObjectByQuery(tomQuery); Assert.assertEquals(1, tim.getFriends().size()); broker.close(); } Succeeds. ODMG Implementation... public void testRequestFriendODMG() throws Exception { Implementation odmg = OJB.getInstance(); Database db = odmg.newDatabase(); db.open("default", Database.OPEN_READ_WRITE); Tra
Re: N same class mapping question...
On Tuesday, October 14, 2003, at 10:29 AM, [EMAIL PROTECTED] wrote: I bet this is the problem. You'd probably better use one of the managed collections. Could you please check by outputting xxx.getClass().getName() somewhere? On retrieved collections it uses: .org.apache.ojb.broker.util.collections.RemovalAwareCollection F Time: 2.508 If 'one' is a non-manageable collection, such as Vector, then 'one' does not get marked as dirty, so it won't be stored. (Just a guess, maybe someelse can tell you more exactly.) On new objects it is an ArrayList, on retrieved objects a RemovalAwareCollection I tried changing the collection-class to org.apache.ojb.broker.util.collections.ManageableArrayList but have the same results: public void testRequestFriend() throws Exception { Unit unit = Unit.begin(); one = UserRepository.findById(one.getId(), unit); two = UserRepository.findById(two.getId(), unit); System.err.println(one.getFriends().getClass().getName()); one.addFriend(two); unit.commit(); TestTools.clearCache(); unit = Unit.begin(); one = UserRepository.findById(one.getId(), unit); List friends = one.getFriends(); System.err.println(friends.getClass().getName()); Assert.assertEquals(1, one.getFriends().size()); unit.commit(); } - org.apache.ojb.broker.util.collections.ManageableArrayList org.apache.ojb.broker.util.collections.ManageableArrayList F Time: 2.732 There was 1 failure: 1) testRequestFriend(org.skife.kim.model.TestUserRelations)junit.framework. AssertionFailedError: expected:<1> but was:<0> at org.skife.kim.model.TestUserRelations.testRequestFriend(TestUserRelation s.java:79) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav a:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor Impl.java:25) at com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java: 12) FAILURES!!! Tests run: 1, Failures: 1, Errors: 0 Hmm Using the PB API to do the same thing... public void testRequestFriendPB() throws Exception { PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker(); Criteria tomCrit = new Criteria(); tomCrit.addEqualTo("id", one.getId()); Query tomQuery = new QueryByCriteria(User.class, tomCrit); User tom = (User) broker.getObjectByQuery(tomQuery); Criteria mikeCrit = new Criteria(); mikeCrit.addEqualTo("id", one.getId()); Query mikeQuery = new QueryByCriteria(User.class, mikeCrit); User mike = (User) broker.getObjectByQuery(mikeQuery); Assert.assertNotNull(tom); Assert.assertNotNull(mike); tom.addFriend(mike); broker.store(tom); broker.clearCache(); User tim = (User) broker.getObjectByQuery(tomQuery); Assert.assertEquals(1, tim.getFriends().size()); broker.close(); } Succeeds. ODMG Implementation... public void testRequestFriendODMG() throws Exception { Implementation odmg = OJB.getInstance(); Database db = odmg.newDatabase(); db.open("default", Database.OPEN_READ_WRITE); Transaction tx = odmg.newTransaction(); tx.begin(); OQLQuery tomQuery = odmg.newOQLQuery(); tomQuery.create("select tom from " + User.class.getName() + " where id = $1"); tomQuery.bind(one.getId()); DList results = (DList) tomQuery.execute(); User tom = (User) results.iterator().next(); OQLQuery mikeQuery = odmg.newOQLQuery(); mikeQuery.create("select mike from " + User.class.getName() + " where id = $1"); mikeQuery.bind(two.getId()); results = (DList) mikeQuery.execute(); User mike = (User) results.iterator().next(); tom.addFriend(mike); tx.commit(); PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker(); broker.clearCache(); broker.close(); tx = odmg.newTransaction(); tx.begin(); OQLQuery timQuery = odmg.newOQLQuery(); timQuery.create("select tom from " + User.class.getName() + " where id = $1"); timQuery.bind(one.getId()); results = (DList) timQuery.execute(); User tim = (User) results.iterator().next(); Assert.assertEquals(1, tim.getFriends().size()); tx.commit(); } Also succeeds. The explicit OTM implementation.. public void testRequestFriendOTM() throws Exception { OTMConnection conn = SimpleKit.getInstance().acquireConnection(PersistenceBrokerFactory.getDe faultKey()); org.apache.ojb.otm.core.Transaction tx = SimpleKit.getInstance().getTransaction(conn); tx.begin(); EnhancedOQLQuery tomQuery = conn.newOQLQuery(); tomQuery.crea
RE: N same class mapping question...
Hello Brian, > -Original Message- > From: Brian McCallister [mailto:[EMAIL PROTECTED] > > Which concrete class is instantiated > > for the list field? > > Default - I don't specify anything so should be a Vector. I bet this is the problem. You'd probably better use one of the managed collections. Could you please check by outputting xxx.getClass().getName() somewhere? I do not know much about OJB's implementation of OTM, so I can only guess from what I know about other JDO/ODMG implementations. see below. > > Can you post the code that you use > The Test: (one and two are created in the setup and removed in the > teardown) > - > public void testRequestFriend() throws Exception > { > Unit unit = Unit.begin(); > one = UserRepository.findById(one.getId(), unit); > two = UserRepository.findById(two.getId(), unit); > one.addFriend(two); If 'one' is a non-manageable collection, such as Vector, then 'one' does not get marked as dirty, so it won't be stored. (Just a guess, maybe someelse can tell you more exactly.) > unit.commit(); > > TestTools.clearCache(); > > unit = Unit.begin(); > one = UserRepository.findById(one.getId(), unit); > List friends = one.getFriends(); > Assert.assertEquals(1, one.getFriends().size()); > // This > Assertion Fails > unit.commit(); > } Olli - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: N same class mapping question...
On Tuesday, October 14, 2003, at 09:33 AM, [EMAIL PROTECTED] wrote: Hej Brian, -Original Message- From: Brian McCallister [mailto:[EMAIL PROTECTED] I have mixed and matched the value, but it hasn't mattered. I had thought it might care so I tried various combinations. It in this vase being a nebulous entity who thwarts my plans, as to my knowledge neither OJB nor Postgres care about case of table names. Which API do you use? OTM (with OQL and Iterators instead of DLists -- see findById(...) below ). The project is part of my OTM learning process so I can write some docs on it. Which concrete class is instantiated for the list field? Default - I don't specify anything so should be a Vector. Can you post the code that you use to persist the objects? Of course, I will put a tarball ( http://kasparov.skife.org/kim-broken.tar.gz (includes jars so is big, 8 megs)) of the whole project up, the relevent pieces: Test Failure: --- There was 1 failure: 1) testRequestFriend(org.skife.kim.model.TestUserRelations)junit.framework. AssertionFailedError: expected:<1> but was:<0> at org.skife.kim.model.TestUserRelations.testRequestFriend(TestUserRelation s.java:76) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav a:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor Impl.java:25) at com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java: 12) --- FAILURES!!! Tests run: 1, Failures: 1, Errors: 0 The Test: (one and two are created in the setup and removed in the teardown) - public void testRequestFriend() throws Exception { Unit unit = Unit.begin(); one = UserRepository.findById(one.getId(), unit); two = UserRepository.findById(two.getId(), unit); one.addFriend(two); unit.commit(); TestTools.clearCache(); unit = Unit.begin(); one = UserRepository.findById(one.getId(), unit); List friends = one.getFriends(); Assert.assertEquals(1, one.getFriends().size()); // This Assertion Fails unit.commit(); } --- Unit simply provides a convenience wrapper around OTMConnections and Transactions: -- package org.skife.kim.infra; import org.apache.ojb.otm.core.Transaction; import org.apache.ojb.otm.OTMConnection; import org.apache.ojb.otm.kit.SimpleKit; import org.apache.ojb.broker.PersistenceBrokerFactory; /** * Unit of Work shortened for typing purposes * * TODO: Add a factory method that takes a long argument and will rollback the transaction * after an elapsed time has passed. Each getConnection() call extends the time * by the initial value. This allows for clearing the connection before the session * times out in web apps */ public class Unit { private Transaction transaction; private OTMConnection connection; private Unit() { this.connection = SimpleKit.getInstance().acquireConnection(PersistenceBrokerFactory.getDe faultKey()); this.transaction = SimpleKit.getInstance().getTransaction(this.connection); } public static Unit begin() { Unit unit = new Unit(); unit.transaction.begin(); return unit; } /** * @throws org.skife.kim.infra.UnitException if the Unit of Work has already been committed * or rolled back - either via this or the underlying * Transaction/OTMConnection */ public void commit() throws UnitException { if (! transaction.isInProgress()) { throw new UnitException("Unit of work already closed"); } this.transaction.commit(); this.connection.close(); } /** * @throws org.skife.kim.infra.UnitException if the Unit of Work has already been committed * or rolled back - either via this or the underlying * Transaction/OTMConnection */ public void rollback() throws UnitException { if (! transaction.isInProgress()) { throw new UnitException("Unit of work already closed"); } this.transaction.rollback(); this.connection.close(); } /** * @return the OTMConnection in use by this Unit. It is already transactional */ OTMConnection getConnection() { return this.connection; } } - The findById(...) used to retrieve the User instances: --- public static User findById(Integer id, Unit unit) throws UnitException { try { EnhancedOQLQuery query = unit.getConnection().newOQLQuery(); query.create("select allprofiles from "
RE: N same class mapping question...
Hej Brian, > -Original Message- > From: Brian McCallister [mailto:[EMAIL PROTECTED] > > I have mixed and matched the value, but it hasn't mattered. I had > thought it might care so I tried various combinations. It in > this vase > being a nebulous entity who thwarts my plans, as to my knowledge > neither OJB nor Postgres care about case of table names. Which API do you use? Which concrete class is instantiated for the list field? Can you post the code that you use to persist the objects? Olli - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: N same class mapping question...
I have mixed and matched the value, but it hasn't mattered. I had thought it might care so I tried various combinations. It in this vase being a nebulous entity who thwarts my plans, as to my knowledge neither OJB nor Postgres care about case of table names. Will experiment on that one further =) -Brian On Tuesday, October 14, 2003, at 08:42 AM, [EMAIL PROTECTED] wrote: Hello Brian, -Original Message- [..] -- Schema Def'n -- [..] Why is 'users' lower-case here and uppercase above? Might cause problems depending on the RDMBS. Olli - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: N same class mapping question...
Hello Brian, > -Original Message- > [..] > -- Schema Def'n -- > > [..] > Why is 'users' lower-case here and uppercase above? Might cause problems depending on the RDMBS. > > > Olli - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]