Re: Problems saving a m:n relationship
Aye, readonly will do it! I had to look in the source code for SequenceManagerNativeImpl to the extractIdentityColumnField() method. Try it! You'll like it! private FieldDescriptor extractIdentityColumnField(ClassDescriptor cld) { FieldDescriptor[] pkFields = cld.getPkFields(); for (int i = 0; i < pkFields.length; i++) { // to find the identity column we search for a autoincrement // read-only field if (pkFields[i].isAutoIncrement() && pkFields[i].isAccessReadOnly()) { return pkFields[i]; } } return null; } From: "Stijn de Witt" <[EMAIL PROTECTED]> Reply-To: "OJB Users List" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Subject: Re: Problems saving a m:n relationship Date: Wed, 14 Apr 2004 15:52:35 +0200 Hi Glenn, Thanks for your message. I had just completed converting the sequencemanager to HighLow and setting autoincrement to "ojb", and that seems to fix it, however, I find this solution less elegant, because the sequencemanager is ojb-specific and I would like to keep the base db model approachable form multiple persistence layers. In short, I'd like to keep the responsibility for generating the database id's in the database. > OK. If you're having the DB assign the PK value, then you need an attribute > "autoincrement="true"" and "access="readonly"" in the field descriptor. > Upon insert, that'll fire the OJB code that retrieves the value assigned and > updates the data model. Interesting, this access="readonly" stuff...I didn't have that set...Maybe that was the cause? Also I had autoincrement set to "database" in my XDoclet comments. I'll reconvert it back and see if this was the culprit. Thanks for your time! -Stijn P.S. To my understanding I should use the NativeImpl sequence manager for - Original Message - From: "Glenn Barnard" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, April 14, 2004 3:06 PM Subject: Re: Problems saving a m:n relationship > Just a stab at trying to help. Hopefully I have read your problem statement > correctly. > > I'm using auto increment for a MS SQL Server 2000 DB. It needs rc6--but > that's just MS SQL Server. > > OK. If you're having the DB assign the PK value, then you need an attribute > "autoincrement="true"" and "access="readonly"" in the field descriptor. > Upon insert, that'll fire the OJB code that retrieves the value assigned and > updates the data model. > > > >From: Armin Waibel <[EMAIL PROTECTED]> > >Reply-To: "OJB Users List" <[EMAIL PROTECTED]> > >To: OJB Users List <[EMAIL PROTECTED]> > >Subject: Re: Problems saving a m:n relationship > >Date: Wed, 14 Apr 2004 12:20:57 +0200 > > > >Hi Stijn, > > > > > Is it recommended to use mysql's auto-increment with OJB? If so, what am > >I > > > doing wrong? If not, what other approach might you suggest? > > > > > > >hmm, it should work. Your code seems ok. In OJB junit test suite we have > >one test using Identity column based PK fields. You can find this test in > >[db-ojb]/src/test/org/.../broker/sequence/NativeIdentifierTest > >This test works for hsql and mysql and use SequenceManagerNativeImpl as > >sequence-manager in jdbc-connection-decriptor (in test the SM was set at > >runtime). The metadata mappings can be found in > >repository_junit_meta_seq.xml file. > >I never try to store m:n relations using SequenceManagerNativeImpl, but it > >work for 1:n relation, thus I assume it will work for m:n too. > > > >regards, > >Armin > > > >Stijn de Witt wrote: > >>Ok, I have fixed my versioning problems. I can access the new > >>PersistenceBroker methods and the code runs. To rule out any website > >>related > >>sideeffects, and to get more info about what is happening, I have created > >>a > >>separate test app and set debugging levels more verbose. > >>The test code looks like this: > >> > >>- > >> public static void main(String[] args) > >> { > >> logger.info("main: Starting..."); > >> PropertyConfigurator.configure(args[0]); > >> > >> logger.info("main: Getting persistence broker..."); > >> PersistenceBroker broker = null; > >> try > >> { > >> broker = PersistenceBrokerFactory.defaultPer
Re: Problems saving a m:n relationship
Hi Glenn, Thanks for your message. I had just completed converting the sequencemanager to HighLow and setting autoincrement to "ojb", and that seems to fix it, however, I find this solution less elegant, because the sequencemanager is ojb-specific and I would like to keep the base db model approachable form multiple persistence layers. In short, I'd like to keep the responsibility for generating the database id's in the database. > OK. If you're having the DB assign the PK value, then you need an attribute > "autoincrement="true"" and "access="readonly"" in the field descriptor. > Upon insert, that'll fire the OJB code that retrieves the value assigned and > updates the data model. Interesting, this access="readonly" stuff...I didn't have that set...Maybe that was the cause? Also I had autoincrement set to "database" in my XDoclet comments. I'll reconvert it back and see if this was the culprit. Thanks for your time! -Stijn P.S. To my understanding I should use the NativeImpl sequence manager for - Original Message - From: "Glenn Barnard" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, April 14, 2004 3:06 PM Subject: Re: Problems saving a m:n relationship > Just a stab at trying to help. Hopefully I have read your problem statement > correctly. > > I'm using auto increment for a MS SQL Server 2000 DB. It needs rc6--but > that's just MS SQL Server. > > OK. If you're having the DB assign the PK value, then you need an attribute > "autoincrement="true"" and "access="readonly"" in the field descriptor. > Upon insert, that'll fire the OJB code that retrieves the value assigned and > updates the data model. > > > >From: Armin Waibel <[EMAIL PROTECTED]> > >Reply-To: "OJB Users List" <[EMAIL PROTECTED]> > >To: OJB Users List <[EMAIL PROTECTED]> > >Subject: Re: Problems saving a m:n relationship > >Date: Wed, 14 Apr 2004 12:20:57 +0200 > > > >Hi Stijn, > > > > > Is it recommended to use mysql's auto-increment with OJB? If so, what am > >I > > > doing wrong? If not, what other approach might you suggest? > > > > > > >hmm, it should work. Your code seems ok. In OJB junit test suite we have > >one test using Identity column based PK fields. You can find this test in > >[db-ojb]/src/test/org/.../broker/sequence/NativeIdentifierTest > >This test works for hsql and mysql and use SequenceManagerNativeImpl as > >sequence-manager in jdbc-connection-decriptor (in test the SM was set at > >runtime). The metadata mappings can be found in > >repository_junit_meta_seq.xml file. > >I never try to store m:n relations using SequenceManagerNativeImpl, but it > >work for 1:n relation, thus I assume it will work for m:n too. > > > >regards, > >Armin > > > >Stijn de Witt wrote: > >>Ok, I have fixed my versioning problems. I can access the new > >>PersistenceBroker methods and the code runs. To rule out any website > >>related > >>sideeffects, and to get more info about what is happening, I have created > >>a > >>separate test app and set debugging levels more verbose. > >>The test code looks like this: > >> > >>- > >> public static void main(String[] args) > >> { > >> logger.info("main: Starting..."); > >> PropertyConfigurator.configure(args[0]); > >> > >> logger.info("main: Getting persistence broker..."); > >> PersistenceBroker broker = null; > >> try > >> { > >> broker = PersistenceBrokerFactory.defaultPersistenceBroker(); > >> > >> logger.info("main: Assigning data to persistent objects..."); > >> Person person = new Person(); > >> Address address = new Address(); > >> person.getAddresses().add(address); > >> > >> person.setFirstName("stijn"); > >> person.setMiddleName("de"); > >> person.setLastName("Witt"); > >> address.setStreet("Graafseweg"); > >> address.setHouseNr("7"); > >> > >> logger.info("main: Starting transaction..."); > >> broker.beginTransaction(); > >> Address tmp; > >> Iterator it = person.getAddresses().iterator(); > >
Re: Problems saving a m:n relationship
Just a stab at trying to help. Hopefully I have read your problem statement correctly. I'm using auto increment for a MS SQL Server 2000 DB. It needs rc6--but that's just MS SQL Server. OK. If you're having the DB assign the PK value, then you need an attribute "autoincrement="true"" and "access="readonly"" in the field descriptor. Upon insert, that'll fire the OJB code that retrieves the value assigned and updates the data model. From: Armin Waibel <[EMAIL PROTECTED]> Reply-To: "OJB Users List" <[EMAIL PROTECTED]> To: OJB Users List <[EMAIL PROTECTED]> Subject: Re: Problems saving a m:n relationship Date: Wed, 14 Apr 2004 12:20:57 +0200 Hi Stijn, > Is it recommended to use mysql's auto-increment with OJB? If so, what am I > doing wrong? If not, what other approach might you suggest? > hmm, it should work. Your code seems ok. In OJB junit test suite we have one test using Identity column based PK fields. You can find this test in [db-ojb]/src/test/org/.../broker/sequence/NativeIdentifierTest This test works for hsql and mysql and use SequenceManagerNativeImpl as sequence-manager in jdbc-connection-decriptor (in test the SM was set at runtime). The metadata mappings can be found in repository_junit_meta_seq.xml file. I never try to store m:n relations using SequenceManagerNativeImpl, but it work for 1:n relation, thus I assume it will work for m:n too. regards, Armin Stijn de Witt wrote: Ok, I have fixed my versioning problems. I can access the new PersistenceBroker methods and the code runs. To rule out any website related sideeffects, and to get more info about what is happening, I have created a separate test app and set debugging levels more verbose. The test code looks like this: - public static void main(String[] args) { logger.info("main: Starting..."); PropertyConfigurator.configure(args[0]); logger.info("main: Getting persistence broker..."); PersistenceBroker broker = null; try { broker = PersistenceBrokerFactory.defaultPersistenceBroker(); logger.info("main: Assigning data to persistent objects..."); Person person = new Person(); Address address = new Address(); person.getAddresses().add(address); person.setFirstName("stijn"); person.setMiddleName("de"); person.setLastName("Witt"); address.setStreet("Graafseweg"); address.setHouseNr("7"); logger.info("main: Starting transaction..."); broker.beginTransaction(); Address tmp; Iterator it = person.getAddresses().iterator(); while (it.hasNext()) { logger.info("main: Store address..."); broker.store(it.next()); } logger.info("main: Store person..."); broker.store(person); broker.serviceBrokerHelper().link(person, true); logger.info("main: Commit transaction..."); broker.commitTransaction(); } catch(Exception e) { logger.error("main: ERROR getting persistence broker:"); logger.error("main: " + e.getMessage()); } logger.info("main: Done."); } - Here is a fragment of the output: - 2004-04-14 11:41:48,500 [main] DEBUG ConnectionFactoryAbstractImpl - Create new connection using DriverManager: [EMAIL PROTECTED] 2004-04-14 11:41:48,500 [main] DEBUG ConnectionManagerImpl - Request new connection from ConnectionFactory: [EMAIL PROTECTED] 2004-04-14 11:41:48,500 [main] DEBUG ConnectionManagerImpl - localBegin was called for con [EMAIL PROTECTED] 2004-04-14 11:41:48,500 [main] DEBUG ConnectionManagerImpl - Try to change autoCommit state to 'false' 2004-04-14 11:41:48,500 [main] INFO OjbTester - main: Store address... 2004-04-14 11:41:48,531 [main] DEBUG JdbcAccessImpl - executeInsert : [EMAIL PROTECTED] 2004-04-14 11:41:48,531 [main] DEBUG SqlGeneratorDefaultImpl - SQL:INSERT INTO bit_Address (id,street,houseNr,zipCode,city,state,country,type) VALUES (?,?,?,?,?,?,?,?) 2004-04-14 11:41:48,546 [main] DEBUG JdbcAccessImpl - executeInsert: [EMAIL PROTECTED]: INSERT INTO bit_Address (id,street,houseNr,zipCode,city,state,country,type) VALUES (0,'Graafseweg','7','','','','',null) 2004-04-14 11:41:48,562 [main] DEBUG StatementManager - closeResources was called 2004-04-14 11:41:48,562 [main] INFO CacheDistributor - Create new ObjectCacheImplementation for 'default' 2004-04-14 11:41:48,562 [main] INFO OjbTester - main: Store person... 2004-04-14 11:41:48,562 [main] DEBUG JdbcAccessImpl - ex
Re: Problems saving a m:n relationship
EBUG JdbcAccessImpl - executeUpdateSQL: DELETE FROM bit_PersonEmailAddress WHERE personId=? 2004-04-14 11:41:48,640 [main] DEBUG StatementManager - closeResources was called 2004-04-14 11:41:48,640 [main] DEBUG SqlGeneratorDefaultImpl - SQL:DELETE FROM bit_PersonPhoneNumber WHERE personId=? 2004-04-14 11:41:48,640 [main] DEBUG JdbcAccessImpl - executeUpdateSQL: DELETE FROM bit_PersonPhoneNumber WHERE personId=? 2004-04-14 11:41:48,671 [main] DEBUG StatementManager - closeResources was called 2004-04-14 11:41:48,671 [main] DEBUG JdbcAccessImpl - executeInsert : [EMAIL PROTECTED] 2004-04-14 11:41:48,687 [main] DEBUG JdbcAccessImpl - executeInsert: [EMAIL PROTECTED]: INSERT INTO bit_Address (id,street,houseNr,zipCode,city,state,country,type) VALUES (0,'Graafseweg','7','','','','',null) 2004-04-14 11:41:48,687 [main] DEBUG StatementManager - closeResources was called 2004-04-14 11:41:48,687 [main] DEBUG SqlGeneratorDefaultImpl - SQL:SELECT addressId FROM bit_PersonAddress WHERE personId=? 2004-04-14 11:41:48,687 [main] DEBUG JdbcAccessImpl - executeSQL: SELECT addressId FROM bit_PersonAddress WHERE personId=? 2004-04-14 11:41:48,750 [main] DEBUG SqlGeneratorDefaultImpl - SQL:DELETE FROM bit_PersonEmailAddress WHERE personId=? 2004-04-14 11:41:48,750 [main] DEBUG JdbcAccessImpl - executeUpdateSQL: DELETE FROM bit_PersonEmailAddress WHERE personId=? 2004-04-14 11:41:48,750 [main] DEBUG StatementManager - closeResources was called 2004-04-14 11:41:48,750 [main] DEBUG SqlGeneratorDefaultImpl - SQL:DELETE FROM bit_PersonPhoneNumber WHERE personId=? 2004-04-14 11:41:48,750 [main] DEBUG JdbcAccessImpl - executeUpdateSQL: DELETE FROM bit_PersonPhoneNumber WHERE personId=? 2004-04-14 11:41:48,750 [main] DEBUG StatementManager - closeResources was called 2004-04-14 11:41:48,750 [main] DEBUG SqlGeneratorDefaultImpl - SQL:INSERT INTO bit_PersonAddress (personId,addressId) VALUES (?,?) 2004-04-14 11:41:48,750 [main] DEBUG JdbcAccessImpl - executeUpdateSQL: INSERT INTO bit_PersonAddress (personId,addressId) VALUES (?,?) 2004-04-14 11:41:48,750 [main] DEBUG StatementManager - closeResources was called 2004-04-14 11:41:48,750 [main] INFO OjbTester - main: Commit transaction... 2004-04-14 11:41:48,750 [main] DEBUG ConnectionManagerImpl - commit was called 2004-04-14 11:41:48,750 [main] INFO OjbTester - main: Done. - Now I see the insert for address passing an id, which looks wrong to me (since it is an auto-increment column), but it works ok. However, the generated id is never fetched from the database, so it is no wonder that the personId and addressId fields in the link table bit_PersonAddress get set to 0! Is it recommended to use mysql's auto-increment with OJB? If so, what am I doing wrong? If not, what other approach might you suggest? Thanks for all your time, -Stijn - Original Message - From: "Stijn de Witt" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, April 09, 2004 1:32 PM Subject: Problems saving a m:n relationship Hi, I have a problem trying to persist two objects that are related through an indirection table. This is what my tables look like: - PERSON id firstname lastname ... ADDRESS id street housenr ... PERSON_ADDRESS person_id address_id - I have chosen for this construction, because COMPANY can have multiple addresses too, so I don't want a column person_id in ADDRESS. One address doesn't have to be available for multiple PERSON's or COMPANY's or whatever, so it actually is more of a 1:n relationship using an indirection table. So PERSON_ADDRESS will often contain the same person_id multiple times, but not the same address_id. I've read the tutorials, but I don't get it to work. I'll show (a fragment of) our repository_user.xml: - - The generated tables in mysql seem to be ok with me (we actually use OjbDoclet to generate the repository.xml and the SQL) and insertion of a PERSON works fine. However, when we create a new person, add a new Address to it and try to save the person, the following happens: A new record gets created for PERSON fine A new record gets created for ADDRESS fine, but when I set auto-update to true, 2 get created?? A new record gets created for PERSON_ADDRESS, but both the columns person_id and address_id are set to 0. Our save code looks something like this: - Person person = new Person; person.getAddresses().add(new Address()); Implementation impl = OJB.getInstance(); Database db = impl.newDatabase(); db.open("default", Database.OPEN_READ_WRITE); Transaction tx = impl.newTransaction(); tx.begin(); // establish database locks on all root dataobjects tx.lock(person, Transaction.WRITE); // set person and address values // ... tx.c
Re: Problems saving a m:n relationship
On Wed, 14 Apr 2004, Stijn de Witt wrote: > Now I see the insert for address passing an id, which looks wrong to me > (since it is an auto-increment column), but it works ok. However, the > generated id is never fetched from the database, so it is no wonder that the > personId and addressId fields in the link table bit_PersonAddress get set to > 0! If you use native autoincrement (i.e. the column is specififed as autoincrement in MySQL), then you should declare this field as access='readonly' in the repository descriptor (so that OJB does not try to set the field), and use the SequenceManagerNativeImpl (for MySql at least). > Is it recommended to use mysql's auto-increment with OJB? If so, what am I > doing wrong? If not, what other approach might you suggest? Usually you shouldn't. It is often better to let OJB generate the primary key values. The major exception to this rule is when you have other non-OJB apps inserting data into these tables in which case you need database-based primarykey generation (which in MySql 3 and 4 means autoincrement columns). For details on the sequence managers see http://db.apache.org/ojb/sequencemanager.html. BTW, you should perhaps update the OJB xdoclet module from CVS (http://cvs.apache.org/viewcvs/db-ojb/), files xdoclet-1.2.jar, xdoclet-ojb-module-1.2.jar, xjavadoc-1.0.2.jar in the lib folder and xdoclet.xml in the xdocs folder, because I've made some changes to the handling of autoincrement. Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problems saving a m:n relationship
#x27;,'7','','','','',null) 2004-04-14 11:41:48,687 [main] DEBUG StatementManager - closeResources was called 2004-04-14 11:41:48,687 [main] DEBUG SqlGeneratorDefaultImpl - SQL:SELECT addressId FROM bit_PersonAddress WHERE personId=? 2004-04-14 11:41:48,687 [main] DEBUG JdbcAccessImpl - executeSQL: SELECT addressId FROM bit_PersonAddress WHERE personId=? 2004-04-14 11:41:48,750 [main] DEBUG SqlGeneratorDefaultImpl - SQL:DELETE FROM bit_PersonEmailAddress WHERE personId=? 2004-04-14 11:41:48,750 [main] DEBUG JdbcAccessImpl - executeUpdateSQL: DELETE FROM bit_PersonEmailAddress WHERE personId=? 2004-04-14 11:41:48,750 [main] DEBUG StatementManager - closeResources was called 2004-04-14 11:41:48,750 [main] DEBUG SqlGeneratorDefaultImpl - SQL:DELETE FROM bit_PersonPhoneNumber WHERE personId=? 2004-04-14 11:41:48,750 [main] DEBUG JdbcAccessImpl - executeUpdateSQL: DELETE FROM bit_PersonPhoneNumber WHERE personId=? 2004-04-14 11:41:48,750 [main] DEBUG StatementManager - closeResources was called 2004-04-14 11:41:48,750 [main] DEBUG SqlGeneratorDefaultImpl - SQL:INSERT INTO bit_PersonAddress (personId,addressId) VALUES (?,?) 2004-04-14 11:41:48,750 [main] DEBUG JdbcAccessImpl - executeUpdateSQL: INSERT INTO bit_PersonAddress (personId,addressId) VALUES (?,?) 2004-04-14 11:41:48,750 [main] DEBUG StatementManager - closeResources was called 2004-04-14 11:41:48,750 [main] INFO OjbTester - main: Commit transaction... 2004-04-14 11:41:48,750 [main] DEBUG ConnectionManagerImpl - commit was called 2004-04-14 11:41:48,750 [main] INFO OjbTester - main: Done. - Now I see the insert for address passing an id, which looks wrong to me (since it is an auto-increment column), but it works ok. However, the generated id is never fetched from the database, so it is no wonder that the personId and addressId fields in the link table bit_PersonAddress get set to 0! Is it recommended to use mysql's auto-increment with OJB? If so, what am I doing wrong? If not, what other approach might you suggest? Thanks for all your time, -Stijn - Original Message - From: "Stijn de Witt" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, April 09, 2004 1:32 PM Subject: Problems saving a m:n relationship Hi, I have a problem trying to persist two objects that are related through an indirection table. This is what my tables look like: - PERSON id firstname lastname ... ADDRESS id street housenr ... PERSON_ADDRESS person_id address_id - I have chosen for this construction, because COMPANY can have multiple addresses too, so I don't want a column person_id in ADDRESS. One address doesn't have to be available for multiple PERSON's or COMPANY's or whatever, so it actually is more of a 1:n relationship using an indirection table. So PERSON_ADDRESS will often contain the same person_id multiple times, but not the same address_id. I've read the tutorials, but I don't get it to work. I'll show (a fragment of) our repository_user.xml: - - The generated tables in mysql seem to be ok with me (we actually use OjbDoclet to generate the repository.xml and the SQL) and insertion of a PERSON works fine. However, when we create a new person, add a new Address to it and try to save the person, the following happens: A new record gets created for PERSON fine A new record gets created for ADDRESS fine, but when I set auto-update to true, 2 get created?? A new record gets created for PERSON_ADDRESS, but both the columns person_id and address_id are set to 0. Our save code looks something like this: - Person person = new Person; person.getAddresses().add(new Address()); Implementation impl = OJB.getInstance(); Database db = impl.newDatabase(); db.open("default", Database.OPEN_READ_WRITE); Transaction tx = impl.newTransaction(); tx.begin(); // establish database locks on all root dataobjects tx.lock(person, Transaction.WRITE); // set person and address values // ... tx.commit(); db.close(); - A lot of info for a first-time post, I hope this problem sounds familiar to someone here. Thanks, -Stijn - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problems saving a m:n relationship
You were right, I failed to replace a .jar under the WEB-INF/lib dir. thanks. - Original Message - From: "Armin Waibel" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Tuesday, April 13, 2004 5:58 PM Subject: Re: Problems saving a m:n relationship > Stijn de Witt wrote: > > > Hi Armin, all, > > > > I have tried your solutions, but I ran into a problem, because I was working > > with rc4. ojb rc4 doesn't have the .link() method in the ServiceBrokerHelper > > yet. > > So I downloaded rc6, ran the ojb-blank target, inserted my files and created > > a rc6-version of my project. I got it all to build, but at the first > > ojb-related query, I get this in my logging window: > > > > 15:52:11,531 INFO [BaseSubmitter] handleSubmit: Getting persistence > > broker... > > 15:52:12,031 INFO [STDOUT] [BOOT] WARN: > > 15:52:12,031 INFO [STDOUT] Value > > "org.apache.ojb.odmg.collections.DListImpl_2" is illegal for key > > "OqlCollectionClass" (should be a class, using default value > > org.apache.ojb.odmg.collections.DListImpl) > > 15:52:12,359 INFO [STDOUT] [DEFAULT] ERROR: > > 15:52:12,359 INFO [STDOUT] ** > > org.apache.ojb.broker.metadata.RepositoryTags: Tag 'object-cache' is not > > defined. ** > > > > Does this mean anything to you? > > > > this sounds like a classloader problem. Do really replace all ojb-jar > files (and config files) in your app classpath? > > regards, > Armin > > > > Thanks, > > -Stijn > > > > > > - Original Message - > > From: "Armin Waibel" <[EMAIL PROTECTED]> > > To: "OJB Users List" <[EMAIL PROTECTED]> > > Sent: Friday, April 09, 2004 2:00 PM > > Subject: Re: Problems saving a m:n relationship > > > > > > > >>Hi Stijn, > >> > >>a few days ago I wrote some tests for M:N handling in odmg-api and > >>stumble across the same problem (hope we can fix this soon). There are > >>two possible workarounds: > >> > >>Transaction tx = odmg.newTransaction(); > >>tx.begin(); > >>Iterator it = person.getAddresses().iterator(); > >>while(it.hasNext()) > >>{ > >>database.makePersistent(it.next()); > >>} > >>database.makePersistent(person); > >>tx.commit(); > >> > >>or you can use the pb-api to insert your object (this looks a little bit > >>complex, because you have to set auto-update/delete false when using > >>odmg-api): > >> > >>TransactionExt tx = (TransactionExt) odmg.newTransaction(); > >>tx.begin(); > >>PersistenceBroker pb = tx.getBroker(); > >>Iterator it = person.getAddresses().iterator(); > >>while(it.hasNext()) > >>{ > >>pb.store(it.next()); > >>} > >>pb.store(person); > >>pb.serviceBrokerHelper().link(person, true); > >>tx.commit(); > >> > >>Hope this will help you. > >> > >>regards, > >>Armin > >> > >>Stijn de Witt wrote: > >> > >> > >>>Hi, > >>> > >>>I have a problem trying to persist two objects that are related through > > > > an indirection table. This is what my tables look like: > > > >>>- > >>>PERSON > >>>id > >>>firstname > >>>lastname > >>>... > >>> > >>>ADDRESS > >>>id > >>>street > >>>housenr > >>>... > >>> > >>>PERSON_ADDRESS > >>>person_id > >>>address_id > >>>- > >>> > >>> > >>>I have chosen for this construction, because COMPANY can have multiple > > > > addresses too, so I don't want a column person_id in ADDRESS. One address > > doesn't have to be available for multiple PERSON's or COMPANY's or whatever, > > so it actually is more of a 1:n relationship using an indirection table. So > > PERSON_ADDRESS will often contain the same person_id multiple times, but not > > the same address_id. > > > >>>I've read the tutorials, but I don't get it to work. I'll show (a > > > > fragment of) our repository_user.xml: > > > >>> > >>>- > >>> >>>class="nl.bergland.codamo.Address" > >>>table="bit_Address" > >>> > >>> >>>
Re: Problems saving a m:n relationship
Stijn de Witt wrote: Hi Armin, all, I have tried your solutions, but I ran into a problem, because I was working with rc4. ojb rc4 doesn't have the .link() method in the ServiceBrokerHelper yet. So I downloaded rc6, ran the ojb-blank target, inserted my files and created a rc6-version of my project. I got it all to build, but at the first ojb-related query, I get this in my logging window: 15:52:11,531 INFO [BaseSubmitter] handleSubmit: Getting persistence broker... 15:52:12,031 INFO [STDOUT] [BOOT] WARN: 15:52:12,031 INFO [STDOUT] Value "org.apache.ojb.odmg.collections.DListImpl_2" is illegal for key "OqlCollectionClass" (should be a class, using default value org.apache.ojb.odmg.collections.DListImpl) 15:52:12,359 INFO [STDOUT] [DEFAULT] ERROR: 15:52:12,359 INFO [STDOUT] ** org.apache.ojb.broker.metadata.RepositoryTags: Tag 'object-cache' is not defined. ** Does this mean anything to you? this sounds like a classloader problem. Do really replace all ojb-jar files (and config files) in your app classpath? regards, Armin Thanks, -Stijn - Original Message - From: "Armin Waibel" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Friday, April 09, 2004 2:00 PM Subject: Re: Problems saving a m:n relationship Hi Stijn, a few days ago I wrote some tests for M:N handling in odmg-api and stumble across the same problem (hope we can fix this soon). There are two possible workarounds: Transaction tx = odmg.newTransaction(); tx.begin(); Iterator it = person.getAddresses().iterator(); while(it.hasNext()) { database.makePersistent(it.next()); } database.makePersistent(person); tx.commit(); or you can use the pb-api to insert your object (this looks a little bit complex, because you have to set auto-update/delete false when using odmg-api): TransactionExt tx = (TransactionExt) odmg.newTransaction(); tx.begin(); PersistenceBroker pb = tx.getBroker(); Iterator it = person.getAddresses().iterator(); while(it.hasNext()) { pb.store(it.next()); } pb.store(person); pb.serviceBrokerHelper().link(person, true); tx.commit(); Hope this will help you. regards, Armin Stijn de Witt wrote: Hi, I have a problem trying to persist two objects that are related through an indirection table. This is what my tables look like: - PERSON id firstname lastname ... ADDRESS id street housenr ... PERSON_ADDRESS person_id address_id - I have chosen for this construction, because COMPANY can have multiple addresses too, so I don't want a column person_id in ADDRESS. One address doesn't have to be available for multiple PERSON's or COMPANY's or whatever, so it actually is more of a 1:n relationship using an indirection table. So PERSON_ADDRESS will often contain the same person_id multiple times, but not the same address_id. I've read the tutorials, but I don't get it to work. I'll show (a fragment of) our repository_user.xml: - - The generated tables in mysql seem to be ok with me (we actually use OjbDoclet to generate the repository.xml and the SQL) and insertion of a PERSON works fine. However, when we create a new person, add a new Address to it and try to save the person, the following happens: A new record gets created for PERSON fine A new record gets created for ADDRESS fine, but when I set auto-update to true, 2 get created?? A new record gets created for PERSON_ADDRESS, but both the columns person_id and address_id are set to 0. Our save code looks something like this: - Person person = new Person; person.getAddresses().add(new Address()); Implementation impl = OJB.getInstance(); Database db = impl.newDatabase(); db.open("default", Database.OPEN_READ_WRITE); Transaction tx = impl.newTransaction(); tx.begin(); // establish database locks on all root dataobjects tx.lock(person, Transaction.WRITE); // set person and address values // ... tx.commit(); db.close(); - A lot of info for a first-time post, I hope this problem sounds familiar to someone here. Thanks, -Stijn - 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] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problems saving a m:n relationship
Hi Armin, all, I have tried your solutions, but I ran into a problem, because I was working with rc4. ojb rc4 doesn't have the .link() method in the ServiceBrokerHelper yet. So I downloaded rc6, ran the ojb-blank target, inserted my files and created a rc6-version of my project. I got it all to build, but at the first ojb-related query, I get this in my logging window: 15:52:11,531 INFO [BaseSubmitter] handleSubmit: Getting persistence broker... 15:52:12,031 INFO [STDOUT] [BOOT] WARN: 15:52:12,031 INFO [STDOUT] Value "org.apache.ojb.odmg.collections.DListImpl_2" is illegal for key "OqlCollectionClass" (should be a class, using default value org.apache.ojb.odmg.collections.DListImpl) 15:52:12,359 INFO [STDOUT] [DEFAULT] ERROR: 15:52:12,359 INFO [STDOUT] ** org.apache.ojb.broker.metadata.RepositoryTags: Tag 'object-cache' is not defined. ** Does this mean anything to you? Thanks, -Stijn - Original Message - From: "Armin Waibel" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Friday, April 09, 2004 2:00 PM Subject: Re: Problems saving a m:n relationship > Hi Stijn, > > a few days ago I wrote some tests for M:N handling in odmg-api and > stumble across the same problem (hope we can fix this soon). There are > two possible workarounds: > > Transaction tx = odmg.newTransaction(); > tx.begin(); > Iterator it = person.getAddresses().iterator(); > while(it.hasNext()) > { > database.makePersistent(it.next()); > } > database.makePersistent(person); > tx.commit(); > > or you can use the pb-api to insert your object (this looks a little bit > complex, because you have to set auto-update/delete false when using > odmg-api): > > TransactionExt tx = (TransactionExt) odmg.newTransaction(); > tx.begin(); > PersistenceBroker pb = tx.getBroker(); > Iterator it = person.getAddresses().iterator(); > while(it.hasNext()) > { > pb.store(it.next()); > } > pb.store(person); > pb.serviceBrokerHelper().link(person, true); > tx.commit(); > > Hope this will help you. > > regards, > Armin > > Stijn de Witt wrote: > > > Hi, > > > > I have a problem trying to persist two objects that are related through an indirection table. This is what my tables look like: > > > > - > > PERSON > > id > > firstname > > lastname > > ... > > > > ADDRESS > > id > > street > > housenr > > ... > > > > PERSON_ADDRESS > > person_id > > address_id > > - > > > > > > I have chosen for this construction, because COMPANY can have multiple addresses too, so I don't want a column person_id in ADDRESS. One address doesn't have to be available for multiple PERSON's or COMPANY's or whatever, so it actually is more of a 1:n relationship using an indirection table. So PERSON_ADDRESS will often contain the same person_id multiple times, but not the same address_id. > > I've read the tutorials, but I don't get it to work. I'll show (a fragment of) our repository_user.xml: > > > > > > - > > > class="nl.bergland.codamo.Address" > > table="bit_Address" > > > > > name="id" > > column="id" > > jdbc-type="INTEGER" > > primarykey="true" > > length="11" > > > > > > > > name="street" > > column="street" > > jdbc-type="VARCHAR" > > length="64" > > > > > > > > name="houseNr" > > column="houseNr" > > jdbc-type="VARCHAR" > > length="16" > > > > > > > > > > > > class="nl.bergland.codamo.Person" > > table="bit_Person" > > > > > name="id" > > column="id" > > jdbc-type="INTEGER" > > primarykey="true" > > length="11" > > > > > > > > name="firstName" > > column="firstName" > > jdbc-type="VARCHAR" > > length="24" > > > > > > > > name="lastName" > > column="lastName" > > jdbc-type="VARCHAR" > > length="24" > > > > >
Re: Problems saving a m:n relationship
Hi Armin, Thanks for your helpful response! So if i understand you correctly, OJB's ODMG implementation, at the moment doesn't support fully transparent m:n relations, but it might in the future? The workarounds you showed look ok to me, but I have another question. In the tutorials, the PersistenceBroker API is used for the m:n relationships. OJB also offers JDO support (through a plugin, native later). Could you advise me on the API to use? We were planning on using ODMG because it's 'official', but we don't have enough know-how to make a really informed decision. If you were planning on building a lare portal based on Jetspeed using OJB, what persistence api would you choose? Am I right in thinking that the PersistenceBroker API is the most feature-rich? The official site somehow conveys that to me... Thanks for your answer and I'll try your workarounds immediately! -Stijn - Original Message - From: "Armin Waibel" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Friday, April 09, 2004 2:00 PM Subject: Re: Problems saving a m:n relationship > Hi Stijn, > > a few days ago I wrote some tests for M:N handling in odmg-api and > stumble across the same problem (hope we can fix this soon). There are > two possible workarounds: > > Transaction tx = odmg.newTransaction(); > tx.begin(); > Iterator it = person.getAddresses().iterator(); > while(it.hasNext()) > { > database.makePersistent(it.next()); > } > database.makePersistent(person); > tx.commit(); > > or you can use the pb-api to insert your object (this looks a little bit > complex, because you have to set auto-update/delete false when using > odmg-api): > > TransactionExt tx = (TransactionExt) odmg.newTransaction(); > tx.begin(); > PersistenceBroker pb = tx.getBroker(); > Iterator it = person.getAddresses().iterator(); > while(it.hasNext()) > { > pb.store(it.next()); > } > pb.store(person); > pb.serviceBrokerHelper().link(person, true); > tx.commit(); > > Hope this will help you. > > regards, > Armin > > Stijn de Witt wrote: > > > Hi, > > > > I have a problem trying to persist two objects that are related through an indirection table. This is what my tables look like: > > > > - > > PERSON > > id > > firstname > > lastname > > ... > > > > ADDRESS > > id > > street > > housenr > > ... > > > > PERSON_ADDRESS > > person_id > > address_id > > - > > > > > > I have chosen for this construction, because COMPANY can have multiple addresses too, so I don't want a column person_id in ADDRESS. One address doesn't have to be available for multiple PERSON's or COMPANY's or whatever, so it actually is more of a 1:n relationship using an indirection table. So PERSON_ADDRESS will often contain the same person_id multiple times, but not the same address_id. > > I've read the tutorials, but I don't get it to work. I'll show (a fragment of) our repository_user.xml: > > > > > > - > > > class="nl.bergland.codamo.Address" > > table="bit_Address" > > > > > name="id" > > column="id" > > jdbc-type="INTEGER" > > primarykey="true" > > length="11" > > > > > > > > name="street" > > column="street" > > jdbc-type="VARCHAR" > > length="64" > > > > > > > > name="houseNr" > > column="houseNr" > > jdbc-type="VARCHAR" > > length="16" > > > > > > > > > > > > class="nl.bergland.codamo.Person" > > table="bit_Person" > > > > > name="id" > > column="id" > > jdbc-type="INTEGER" > > primarykey="true" > > length="11" > > > > > > > > name="firstName" > > column="firstName" > > jdbc-type="VARCHAR" > > length="24" > > > > > > > > name="lastName" > > column="lastName" > > jdbc-type="VARCHAR" > > length="24" > > > > > > > > name=&quo
Re: Problems saving a m:n relationship
Hi Stijn, a few days ago I wrote some tests for M:N handling in odmg-api and stumble across the same problem (hope we can fix this soon). There are two possible workarounds: Transaction tx = odmg.newTransaction(); tx.begin(); Iterator it = person.getAddresses().iterator(); while(it.hasNext()) { database.makePersistent(it.next()); } database.makePersistent(person); tx.commit(); or you can use the pb-api to insert your object (this looks a little bit complex, because you have to set auto-update/delete false when using odmg-api): TransactionExt tx = (TransactionExt) odmg.newTransaction(); tx.begin(); PersistenceBroker pb = tx.getBroker(); Iterator it = person.getAddresses().iterator(); while(it.hasNext()) { pb.store(it.next()); } pb.store(person); pb.serviceBrokerHelper().link(person, true); tx.commit(); Hope this will help you. regards, Armin Stijn de Witt wrote: Hi, I have a problem trying to persist two objects that are related through an indirection table. This is what my tables look like: - PERSON id firstname lastname ... ADDRESS id street housenr ... PERSON_ADDRESS person_id address_id - I have chosen for this construction, because COMPANY can have multiple addresses too, so I don't want a column person_id in ADDRESS. One address doesn't have to be available for multiple PERSON's or COMPANY's or whatever, so it actually is more of a 1:n relationship using an indirection table. So PERSON_ADDRESS will often contain the same person_id multiple times, but not the same address_id. I've read the tutorials, but I don't get it to work. I'll show (a fragment of) our repository_user.xml: - - The generated tables in mysql seem to be ok with me (we actually use OjbDoclet to generate the repository.xml and the SQL) and insertion of a PERSON works fine. However, when we create a new person, add a new Address to it and try to save the person, the following happens: A new record gets created for PERSON fine A new record gets created for ADDRESS fine, but when I set auto-update to true, 2 get created?? A new record gets created for PERSON_ADDRESS, but both the columns person_id and address_id are set to 0. Our save code looks something like this: - Person person = new Person; person.getAddresses().add(new Address()); Implementation impl = OJB.getInstance(); Database db = impl.newDatabase(); db.open("default", Database.OPEN_READ_WRITE); Transaction tx = impl.newTransaction(); tx.begin(); // establish database locks on all root dataobjects tx.lock(person, Transaction.WRITE); // set person and address values // ... tx.commit(); db.close(); - A lot of info for a first-time post, I hope this problem sounds familiar to someone here. Thanks, -Stijn - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Problems saving a m:n relationship
Hi, I have a problem trying to persist two objects that are related through an indirection table. This is what my tables look like: - PERSON id firstname lastname ... ADDRESS id street housenr ... PERSON_ADDRESS person_id address_id - I have chosen for this construction, because COMPANY can have multiple addresses too, so I don't want a column person_id in ADDRESS. One address doesn't have to be available for multiple PERSON's or COMPANY's or whatever, so it actually is more of a 1:n relationship using an indirection table. So PERSON_ADDRESS will often contain the same person_id multiple times, but not the same address_id. I've read the tutorials, but I don't get it to work. I'll show (a fragment of) our repository_user.xml: - - The generated tables in mysql seem to be ok with me (we actually use OjbDoclet to generate the repository.xml and the SQL) and insertion of a PERSON works fine. However, when we create a new person, add a new Address to it and try to save the person, the following happens: A new record gets created for PERSON fine A new record gets created for ADDRESS fine, but when I set auto-update to true, 2 get created?? A new record gets created for PERSON_ADDRESS, but both the columns person_id and address_id are set to 0. Our save code looks something like this: - Person person = new Person; person.getAddresses().add(new Address()); Implementation impl = OJB.getInstance(); Database db = impl.newDatabase(); db.open("default", Database.OPEN_READ_WRITE); Transaction tx = impl.newTransaction(); tx.begin(); // establish database locks on all root dataobjects tx.lock(person, Transaction.WRITE); // set person and address values // ... tx.commit(); db.close(); - A lot of info for a first-time post, I hope this problem sounds familiar to someone here. Thanks, -Stijn