[Announce] Clepsydra 0.8
I just wanted to let you know that the first release of Clepsydra a GPL licensed web application for managing and sharing a collection of documents (pictures centric) is out. This can be a sample of OJB usage (good or bad) as it's using OJB and ojb-xdoclet module for persistence. This is for me the opportunity to say that i'am very happy with OJB, and i would like to thank you all for the great framework, and for your help too. Here is the page of the project http://clepsydra.javaforge.com/ http://clepsydra.javaforge.com/screenshots.html Thanks Jean-Yves P.S. : I sent an e-mail similar to this one to the tapestry mailing list as it's used by the application too, and it's great like OJB. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: auto delete and foreign keys
Hi, The problem was solved by setting the foreign key constraint to DEFERRABLE INITIALLY DEFERRED in postgres. So the check of constraints is done only at the end of the transaction, this way OJB is deleting the objects and then the constraints are enforced. Thanks for your help. Jean-Yves On 3/28/06, Jean-Yves Sironneau [EMAIL PROTECTED] wrote: Hi Armin, On 3/27/06, Armin Waibel [EMAIL PROTECTED] wrote: Hi Jean-Yves, Jean-Yves Sironneau wrote: Hello, Yes another question again. I have a class Area that is referencing a class Point, and Area has a foreign key constraint on Point. I'am using ODMG, and i would like OJB to delete the Point when i delete the Area. What happens is that when i commit a transaction for removing an Area, OJB is trying to remove the Point but of course it can't because the foreing key constraint is violated as the Area is still referencing the point. So i suppose the Area should be removed first for this to work. Do you think it can be a bug ? Do i have to manually unreference the point somewhere ? Do you use auto-delete=object in Area 1:1 reference-descriptor to Point? http://db.apache.org/ojb/docu/guides/odmg-guide.html#Specific+Metadata+Settings Yes If you have problems with the order of persistent objects you can A. disable ordering and set object order by hand (first delete Area, then Point) http://db.apache.org/ojb/docu/guides/odmg-guide.html#Disable+OJB%27s+object+ordering%2C+determine+object+order+%22by+hand%22 Yes, but the problem is that i do not explicitely call a delete method on this object, I remove an object that is referencing an Area, and the Area is referencing the Point, this is a cascade delete. B. use a workaround to specify the database FK. Simply set a custom property 'constraint' in reference-descriptor of Area. attribute attribute-name=constraint attribute-value=true/ http://db.apache.org/ojb/docu/guides/odmg-guide.html#Foreign+Keys+Constraints+and+ODMG-api If set OJB's ordering try to take care of the database constraint. I tried but it did not work, here is an extract of the sql statements generated by OJB 1143500067952|0|1|statement||SELECT A0.id,A0.documentBaseId,A0.firstName, A0.lastName ,A0.email,A0.url FROM Person A0 WHERE A0.documentBaseId='27WXcUHNXRZ36EkQnYIQqmHsbqPqX9k9cnOoAyPgbf65g2Cqql' 1143500068124|161|0|statement||DELETE FROM Point WHERE id = 'OmEWtzi9bM9etJISTKWWjKaUlmUTopM6c8W5xGQUN8yKp7HQFs' 1143500068206|1|0|rollback|| What I do not get is that the database foreign key check is deferrable (postgres), so this statement should be ok if followed by the deletion of the Area, but i have to look more precisely at the meaning of deferred in postgres. Anyway if it does not work i will try to reverse the relation and it should work. Thank you. Jean-Yves Thank you. Jean-Yves P.S.: I'am not a foreign key constraint expert, but i tried to use deferrable=true for this constraint and it does not work neither. strange! I would expect that in this case delete ordering is irrelevant. regards, Armin - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: auto delete and foreign keys
Hi Armin, On 3/27/06, Armin Waibel [EMAIL PROTECTED] wrote: Hi Jean-Yves, Jean-Yves Sironneau wrote: Hello, Yes another question again. I have a class Area that is referencing a class Point, and Area has a foreign key constraint on Point. I'am using ODMG, and i would like OJB to delete the Point when i delete the Area. What happens is that when i commit a transaction for removing an Area, OJB is trying to remove the Point but of course it can't because the foreing key constraint is violated as the Area is still referencing the point. So i suppose the Area should be removed first for this to work. Do you think it can be a bug ? Do i have to manually unreference the point somewhere ? Do you use auto-delete=object in Area 1:1 reference-descriptor to Point? http://db.apache.org/ojb/docu/guides/odmg-guide.html#Specific+Metadata+Settings Yes If you have problems with the order of persistent objects you can A. disable ordering and set object order by hand (first delete Area, then Point) http://db.apache.org/ojb/docu/guides/odmg-guide.html#Disable+OJB%27s+object+ordering%2C+determine+object+order+%22by+hand%22 Yes, but the problem is that i do not explicitely call a delete method on this object, I remove an object that is referencing an Area, and the Area is referencing the Point, this is a cascade delete. B. use a workaround to specify the database FK. Simply set a custom property 'constraint' in reference-descriptor of Area. attribute attribute-name=constraint attribute-value=true/ http://db.apache.org/ojb/docu/guides/odmg-guide.html#Foreign+Keys+Constraints+and+ODMG-api If set OJB's ordering try to take care of the database constraint. I tried but it did not work, here is an extract of the sql statements generated by OJB 1143500067952|0|1|statement||SELECT A0.id,A0.documentBaseId,A0.firstName, A0.lastName,A0.email,A0.url FROM Person A0 WHERE A0.documentBaseId='27WXcUHNXRZ36EkQnYIQqmHsbqPqX9k9cnOoAyPgbf65g2Cqql' 1143500068124|161|0|statement||DELETE FROM Point WHERE id = 'OmEWtzi9bM9etJISTKWWjKaUlmUTopM6c8W5xGQUN8yKp7HQFs' 1143500068206|1|0|rollback|| What I do not get is that the database foreign key check is deferrable (postgres), so this statement should be ok if followed by the deletion of the Area, but i have to look more precisely at the meaning of deferred in postgres. Anyway if it does not work i will try to reverse the relation and it should work. Thank you. Jean-Yves Thank you. Jean-Yves P.S.: I'am not a foreign key constraint expert, but i tried to use deferrable=true for this constraint and it does not work neither. strange! I would expect that in this case delete ordering is irrelevant. regards, Armin - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
auto delete and foreign keys
Hello, Yes another question again. I have a class Area that is referencing a class Point, and Area has a foreign key constraint on Point. I'am using ODMG, and i would like OJB to delete the Point when i delete the Area. What happens is that when i commit a transaction for removing an Area, OJB is trying to remove the Point but of course it can't because the foreing key constraint is violated as the Area is still referencing the point. So i suppose the Area should be removed first for this to work. Do you think it can be a bug ? Do i have to manually unreference the point somewhere ? Thank you. Jean-Yves P.S.: I'am not a foreign key constraint expert, but i tried to use deferrable=true for this constraint and it does not work neither.
Re: ODMG locking and read only references
It worked with the SVN version of OJB the objects are not materialized so there is no LockNotGrantedException, by weak reference i meant read only reference to an object, and i that case the referencing object is just interested by the fact is has a relation with the referenced object but not with any of it's attributes. Thanks again for your help. 2006/3/21, Armin Waibel [EMAIL PROTECTED]: Hi Jean-Yves, Jean-Yves Sironneau wrote: Hello, I would like to know if it's possible using ODMG to set auto-update to false for a reference. Because in the documentation it's supposed to be set to none. But none seem's to be true. Sorry, the ODMG implementation expects these specific settings and no it's not allowed to change these settings. The issue is that i have a class Role that has a reference on a DocumentBase, when i lock a Role for updating it, it also locks the referenced DocumentBase, This should only happen if implicit locking is enabled. If you disable implicit locking, e.g. at runtime or in OJB.properties file http://db.apache.org/ojb/docu/guides/odmg-guide.html the referenced objects will not be locked. But nevertheless OJB will make a snapshot of the locked object with all referenced objects. and materialize all the proxied objects within DocumentBase to try to write lock them, OJB should never materialize proxy objects while locking the main object. Think there was a bug in =1.0.4, it's fixed in SVN OJB_1_0_RELEASE and will be included in 1.0.5. If possible please test latest from SVN OJB_1_0_RELEASE branch. and i really don't want that has DocumentBase can be big and it's association with Role is just to say that a Role is for this DocumentBase, and also because it's throwing a LockNotGrantedExcetion. Sounds strange. Could it be that the same DocumentBase will be locked by different tx? One solution would be to store the pk of the DocumentBase in Role, but i would like to know if it's possible by keeping a weak reference to DocumentBase or not. Sorry, I can't see what you mean. How do you currently establish the reference? You always need a FK column to define a 1:1 relation. What do weak reference mean? regards, Armin Thank you. Jean-Yves - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Misc questions
Ok i think i got it, thank you for the explanations. 2006/3/21, Armin Waibel [EMAIL PROTECTED]: Hi Jean-Yves, Jean-Yves Sironneau wrote: Hi, Thanks for your help, it works by locking the object inside a transaction and the setting the referenced object, what confused me is that for a new object you don't have to be within a transaction for the referenced object to be created, but for an existing one this is the case. The first one (new object) works by accident. In general OJB compares object snapshots (one object snapshot made on object lock, another snapshot made on commit), thus OJB can only detect changes when these snapshots are different. If you make changes on an (persistent) object before the object is locked you are lost. When store a new object it's easier for OJB to decide whether the object should be marked as dirty and whether the FK should be refreshed/set - it's always yes. regards, Armin Thank you. Jean-Yves 2006/3/10, Armin Waibel [EMAIL PROTECTED]: Hi Jean-Yves, Jean-Yves Sironneau wrote: Hello, I looked more precisely at my issue regarding foreign keys not being set, so now i'am using official OJB 1.0.4. The exact issue is that when i persist a new object (that has not been persisted before), the linked object is persisted and the foreign key is set. But when i retrieve an object, then sets the linked object and then persists the main object this time the linked object is not persisted and the foreign key not set. I'am using the following code, to do the persistence, so the linked object is set before that code : Implementation impl = OJB.getInstance(); TransactionExt tx = (TransactionExt) impl.newTransaction(); tx.begin(); tx.markDirty(product); tx.commit(); Can that be the reason ? Is the way OJB is navigating the object graph different for an initial store or an update ? If you want i can try to package up a simple test case from that. Do you retrieve the object via oql-query and is implicit locking enabled? If you first lock the object and then set the linked object: Implementation impl = OJB.getInstance(); TransactionExt tx = (TransactionExt) impl.newTransaction(); tx.begin(); tx.lock(obj, WRITE); obj.setLinked(objB); tx.commit(); This way your test should pass. regards, Armin Thank you for your help. Jean-Yves 2006/2/20, Jean-Yves Sironneau [EMAIL PROTECTED]: Hello, I have a few unrelated questions regarding OJB : - Is there a way to set the deferrable foreign key constraint setting using OJB xdoclet module ? - When i use anonymous foreign key in a relationship, it's working perfectly for collections, but for simple reference to an object, i have to store the referenced object and then store the object referencing it, otherwise the two objects are created in db but the foreign key id is not set. It's pretty hard to discover it because, when i retrieve the objects they are ok even if the db foreign key is not set. It's just later, if i restart my application for example, that the referenced objects fields are null. So i have two questions : Do you think it's normal behaviour ? And how can i force OJB to retrieve everything from database to be able to test this kind of possible issues ? By the way i'am using CVS version of OJB 1.1 approximately 2-3 months ago and the ODMG API (which is really working fine except for that). - Is the code for OJB 1.1 located in the 1.0 SVN branch ? Because i don't know if i better use OJB 1.0.4 (or future 1.0.5) or the version i got from CVS. Thanks your for your help. Jean-Yves - 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: Misc questions
I forgot to tell that to raise this issue i have to clear the persistencer cache, otherwise everything seem's to be ok. 2006/3/7, Jean-Yves Sironneau [EMAIL PROTECTED]: Hello, I looked more precisely at my issue regarding foreign keys not being set, so now i'am using official OJB 1.0.4. The exact issue is that when i persist a new object (that has not been persisted before), the linked object is persisted and the foreign key is set. But when i retrieve an object, then sets the linked object and then persists the main object this time the linked object is not persisted and the foreign key not set. I'am using the following code, to do the persistence, so the linked object is set before that code : Implementation impl = OJB.getInstance(); TransactionExt tx = (TransactionExt) impl.newTransaction(); tx.begin(); tx.markDirty(product); tx.commit(); Can that be the reason ? Is the way OJB is navigating the object graph different for an initial store or an update ? If you want i can try to package up a simple test case from that. Thank you for your help. Jean-Yves 2006/2/20, Jean-Yves Sironneau [EMAIL PROTECTED]: Hello, I have a few unrelated questions regarding OJB : - Is there a way to set the deferrable foreign key constraint setting using OJB xdoclet module ? - When i use anonymous foreign key in a relationship, it's working perfectly for collections, but for simple reference to an object, i have to store the referenced object and then store the object referencing it, otherwise the two objects are created in db but the foreign key id is not set. It's pretty hard to discover it because, when i retrieve the objects they are ok even if the db foreign key is not set. It's just later, if i restart my application for example, that the referenced objects fields are null. So i have two questions : Do you think it's normal behaviour ? And how can i force OJB to retrieve everything from database to be able to test this kind of possible issues ? By the way i'am using CVS version of OJB 1.1 approximately 2-3 months ago and the ODMG API (which is really working fine except for that). - Is the code for OJB 1.1 located in the 1.0 SVN branch ? Because i don't know if i better use OJB 1.0.4 (or future 1.0.5) or the version i got from CVS. Thanks your for your help. Jean-Yves
Re: Misc questions
Hello, I looked more precisely at my issue regarding foreign keys not being set, so now i'am using official OJB 1.0.4. The exact issue is that when i persist a new object (that has not been persisted before), the linked object is persisted and the foreign key is set. But when i retrieve an object, then sets the linked object and then persists the main object this time the linked object is not persisted and the foreign key not set. I'am using the following code, to do the persistence, so the linked object is set before that code : Implementation impl = OJB.getInstance(); TransactionExt tx = (TransactionExt) impl.newTransaction(); tx.begin(); tx.markDirty(product); tx.commit(); Can that be the reason ? Is the way OJB is navigating the object graph different for an initial store or an update ? If you want i can try to package up a simple test case from that. Thank you for your help. Jean-Yves 2006/2/20, Jean-Yves Sironneau [EMAIL PROTECTED]: Hello, I have a few unrelated questions regarding OJB : - Is there a way to set the deferrable foreign key constraint setting using OJB xdoclet module ? - When i use anonymous foreign key in a relationship, it's working perfectly for collections, but for simple reference to an object, i have to store the referenced object and then store the object referencing it, otherwise the two objects are created in db but the foreign key id is not set. It's pretty hard to discover it because, when i retrieve the objects they are ok even if the db foreign key is not set. It's just later, if i restart my application for example, that the referenced objects fields are null. So i have two questions : Do you think it's normal behaviour ? And how can i force OJB to retrieve everything from database to be able to test this kind of possible issues ? By the way i'am using CVS version of OJB 1.1 approximately 2-3 months ago and the ODMG API (which is really working fine except for that). - Is the code for OJB 1.1 located in the 1.0 SVN branch ? Because i don't know if i better use OJB 1.0.4 (or future 1.0.5) or the version i got from CVS. Thanks your for your help. Jean-Yves
Re: Help needed for Transaction Rollbacks
I think OTM is kind of deprecated, but i don't know if it's important for this issue. In my mind when you do a commit a transaction, if something fails, no step of the transaction should have been commited, so maybe your database do not support transactions. 2006/2/21, Vamsi Atluri [EMAIL PROTECTED]: Hello all, I tested my own solution suggested below, but it still did not work. The class that I got for connection was : [EMAIL PROTECTED] wrapped [EMAIL PROTECTED] ] Why wouldn't straight commit() and rollback() not work on a Connection? Any help is greatly appreciated. Thank you. Regards, -Vamsi --- Vamsi Atluri [EMAIL PROTECTED] wrote: Hello all, I am having problem with getting my transactions rolled back. I have read the documentation a bit about OTM but I am not clear about what I should do in my situation. I am using OJB1.0.1 for DB2 and running on WAS 5.0 (currently testing on WSAD 5.1.2). My data save code looks something like this: PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker(); try { broker.beginTransaction(); broker.store(objA); //step 1 broker.store(objB); //step 2 broker.store(objC); //step 3 broker.deleteByQuery(someQuery); //step 4 broker.store(objD); //step 5 broker.commitTransaction(); } catch(PersistenceBrokerException pbe) { if(null != broker) { broker.abortTransaction(); } } catch(Exception e) { if(null != broker) { broker.abortTransaction(); } } finally { if(null != broker) { broker.close(); } } It so happens that if there is any Exception during any of the steps, the previous steps are not being rolled back. Is it possible that I can get the ConnectionManager from the broker and use it for managing my transactions? The document says that OJB provides only DB level transactions but not object level transactions. What does that this exactly mean? Do I have to implement OTM (which would be a huge undertaking given the amount of tables we store)? Or can I do something like this: PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker(); java.sql.Connection conn = null; try { ConnectionManagerIF connectionManager = broker.serviceConnectionManager(); conn = connectionManager.getConnection(); conn.setAutoCommit(false); broker.store(objA); //step 1 broker.store(objB); //step 2 broker.store(objC); //step 3 broker.deleteByQuery(someQuery); //step 4 broker.store(objD); //step 5 conn.commit(); } catch(PersistenceBrokerException pbe) { if(null != conn) { conn.rollback(); } } catch(Exception e) { if(null != conn) { conn.rollback(); } } finally { if(null != broker) { broker.close(); } } Any help is greatly appreciated in this matter. Thank you. Regards, -Vamsi - 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]
Misc questions
Hello, I have a few unrelated questions regarding OJB : - Is there a way to set the deferrable foreign key constraint setting using OJB xdoclet module ? - When i use anonymous foreign key in a relationship, it's working perfectly for collections, but for simple reference to an object, i have to store the referenced object and then store the object referencing it, otherwise the two objects are created in db but the foreign key id is not set. It's pretty hard to discover it because, when i retrieve the objects they are ok even if the db foreign key is not set. It's just later, if i restart my application for example, that the referenced objects fields are null. So i have two questions : Do you think it's normal behaviour ? And how can i force OJB to retrieve everything from database to be able to test this kind of possible issues ? By the way i'am using CVS version of OJB 1.1 approximately 2-3 months ago and the ODMG API (which is really working fine except for that). - Is the code for OJB 1.1 located in the 1.0 SVN branch ? Because i don't know if i better use OJB 1.0.4 (or future 1.0.5) or the version i got from CVS. Thanks your for your help. Jean-Yves
Re: big data postgres platform
In fact i'am able to persist my data using an array of bytes like that : /** * @ojb.field */ private byte[] primaryContent; But my problem is that when i retrieve a lot of objects having this type of attribute, i get an OutOfMemory error, and the blob , has i understand it allow to have a reference to the data, but looking at the ojb test suite i see that the blob tests are done the way i do it and not using the Blob interface, am i wrong on that ? Do you think i have to declare my field to type Blob ? And if so is there a way to construct a blob to be able to persit it ? Jean-Yves 2006/1/25, Thomas Dudziak [EMAIL PROTECTED]: On 1/25/06, Jean-Yves Sironneau [EMAIL PROTECTED] wrote: I have a question regarding the handling of large data with ojb on the Postgres platform. - I think Blobs are not supported on this platform, is that true ? - What is the best way to tell ojb to fetch the data from a field on each access to the field ? - Is that better to manage that issue by hand Right now i have an array of bytes as the field corresponding to the big content, it's working pertty well except that i get Out of memory errors because the data stays on the heap. I think, the Postgres driver (at least the new 8 ones) have no problems handling BYTEA columns with the JDBC Blob interface, so you should be able to tell OJB its a Blob and use BYTEA in the database. Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
big data postgres platform
Hello, I have a question regarding the handling of large data with ojb on the Postgres platform. - I think Blobs are not supported on this platform, is that true ? - What is the best way to tell ojb to fetch the data from a field on each access to the field ? - Is that better to manage that issue by hand Right now i have an array of bytes as the field corresponding to the big content, it's working pertty well except that i get Out of memory errors because the data stays on the heap. Thank you for your advices. Jean-Yves
Foreign key not set
Hello, I'am having trouble trying to find out what i am doing wrong, i have a class user and a class role and a user has a collection of roles, this kind of schema is working for other classes with the same kind of relationship but not for this one. OJB is trying to insert a null value in the column of the foreign key id, but the role is in the collection of roles of the user instance. I'am using latest CVS OJB, my two classes are : public class User implements INamable { /** * @ojb.field primarykey=true */ private String id; */** * @ojb.collection element-class-ref=org.jys.clepsydra.data.users.Role * foreignkey=userId auto-delete=true */ private ListRole roles = new VectorRole(); * /** * @ojb.field */ private String url; public User(String name) { this.name = name; } public User() { super(); } /** * @return Returns the roles. */ public ListRole getRoles() { return roles; } /** * @param role * @throws DataIntegrityException */ public void addRole(final Role role) throws DataIntegrityException { if (findRole(role.getDocumentBase()) != null) { throw new DataIntegrityException(this + already has a role for + role.getDocumentBase()); } roles.add(role); } } and public abstract class Role implements IDataObject { /** * @ojb.field primarykey=true */ private String id; /** * @ojb.reference foreignkey=documentBaseId auto-update=none auto-delete=none */ private DocumentBase documentBase; public Role(DocumentBase base) { super(); this.documentBase = base; } public Role() { super(); } public String getId() { return id; } public void setId(String id) { this.id = id; } public DocumentBase getDocumentBase() { return documentBase; } public boolean equals(Object object) { if (object instanceof Role) { return this.id.equals(((IDataObject) object).getId()); } return false; } public String toString() { return this.getClass() + + this.getDocumentBase(); } } and what i am trying to do is Role admin = new Admin(getCurrentBase()); DataHelper.generateId(admin); User t = getTestUser(); t.addRole(admin); DataHelper.store(t); If u have any clue about... Thank you. Jean-Yves sql statement was 'INSERT INTO Admin (userId,documentBaseId,id) VALUES (?,?,?) '. Exception message is [ERREUR: Une valeur NULL dans la colonne «userid» viole la contrainte NOT NULL] Vendor error code [0] SQL state code [23502=NOT NULL VIOLATION] Target class is 'org.jys.clepsydra.data.users.Admin'. PK of the target object is [id=3eg3Lcb;b,YDSW2Eet\B7XX]. Source object: class org.jys.clepsydra.data.users.Admin [EMAIL PROTECTED]trHx` :=36,iVikR@testDocumentBase at org.apache.ojb.broker.util.ExceptionHelper.generateException(ExceptionHelper.java:161) at org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeInsert(JdbcAccessImpl.java:241) at org.apache.ojb.broker.core.PersistenceBrokerImpl.storeToDb(PersistenceBrokerImpl.java:2256) at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(PersistenceBrokerImpl.java:988) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(DelegatingPersistenceBroker.java:172) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(DelegatingPersistenceBroker.java:172) at org.apache.ojb.odmg.ObjectEnvelope.doInsert(ObjectEnvelope.java:767) at org.apache.ojb.odmg.states.StateNewDirty.commit(StateNewDirty.java:106) at org.apache.ojb.odmg.ObjectEnvelopeTable.writeAllEnvelopes(ObjectEnvelopeTable.java:249) at org.apache.ojb.odmg.ObjectEnvelopeTable.writeObjects(ObjectEnvelopeTable.java:185) at org.apache.ojb.odmg.TransactionImpl.doWriteObjects(TransactionImpl.java:384) at org.apache.ojb.odmg.TransactionImpl.prepareCommit(TransactionImpl.java:743) at org.apache.ojb.odmg.TransactionImpl.commit(TransactionImpl.java:679) at org.jys.clepsydra.pers.OJBPersistencer.store(OJBPersistencer.java:69) at $IPersistencer_1072de1a612.store($IPersistencer_1072de1a612.java) at org.jys.clepsydra.DataHelper.store(DataHelper.java:118) at org.jys.clepsydra.testing.tests.TestBaseCreation.testAddRoleToFirstUser(TestBaseCreation.java:197) at org.jys.clepsydra.testing.TestInitService.run(TestInitService.java:31) at $Runnable_1072de1a617.run($Runnable_1072de1a617.java) at $Runnable_1072de1a616.run($Runnable_1072de1a616.java) at org.jys.clepsydra.services.InitService.run(InitService.java:53) at $Runnable_1072de1a611.run($Runnable_1072de1a611.java) at $Runnable_1072de1a610.run($Runnable_1072de1a610.java) at org.jys.clepsydra.DataHelper.init(DataHelper.java:71) at
Re: Foreign key not set
=documentBaseId jdbc-type=VARCHAR nullable=false length=254 access=anonymous /field-descriptor field-descriptor name=id column=id jdbc-type=VARCHAR primarykey=true length=254 /field-descriptor reference-descriptor name=documentBase class-ref=org.jys.clepsydra.data.DocumentBase auto-update=none auto-delete=none foreignkey field-ref=documentBaseId/ /reference-descriptor /class-descriptor Armin Waibel wrote: Hi Jean-Yves, in User the 1:n reference the auto-update setting is undefined and by default OJB use 'link' for 1:n relations, thus I would expect that the FK in Admin will be set. Could you post the generated repository.xml for User, Admin, Role? regards Armin Jean-Yves Sironneau wrote: Hello, I'am having trouble trying to find out what i am doing wrong, i have a class user and a class role and a user has a collection of roles, this kind of schema is working for other classes with the same kind of relationship but not for this one. OJB is trying to insert a null value in the column of the foreign key id, but the role is in the collection of roles of the user instance. I'am using latest CVS OJB, my two classes are : public class User implements INamable { /** * @ojb.field primarykey=true */ private String id; */** * @ojb.collection element-class-ref=org.jys.clepsydra.data.users.Role * foreignkey=userId auto-delete=true */ private ListRole roles = new VectorRole(); * /** * @ojb.field */ private String url; public User(String name) { this.name = name; } public User() { super(); } /** * @return Returns the roles. */ public ListRole getRoles() { return roles; } /** * @param role * @throws DataIntegrityException */ public void addRole(final Role role) throws DataIntegrityException { if (findRole(role.getDocumentBase()) != null) { throw new DataIntegrityException(this + already has a role for + role.getDocumentBase()); } roles.add(role); } } and public abstract class Role implements IDataObject { /** * @ojb.field primarykey=true */ private String id; /** * @ojb.reference foreignkey=documentBaseId auto-update=none auto-delete=none */ private DocumentBase documentBase; public Role(DocumentBase base) { super(); this.documentBase = base; } public Role() { super(); } public String getId() { return id; } public void setId(String id) { this.id = id; } public DocumentBase getDocumentBase() { return documentBase; } public boolean equals(Object object) { if (object instanceof Role) { return this.id.equals(((IDataObject) object).getId()); } return false; } public String toString() { return this.getClass() + + this.getDocumentBase(); } } and what i am trying to do is Role admin = new Admin(getCurrentBase()); DataHelper.generateId(admin); User t = getTestUser(); t.addRole(admin); DataHelper.store(t); If u have any clue about... Thank you. Jean-Yves sql statement was 'INSERT INTO Admin (userId,documentBaseId,id) VALUES (?,?,?) '. Exception message is [ERREUR: Une valeur NULL dans la colonne «userid» viole la contrainte NOT NULL] Vendor error code [0] SQL state code [23502=NOT NULL VIOLATION] Target class is 'org.jys.clepsydra.data.users.Admin'. PK of the target object is [id=3eg3Lcb;b,YDSW2Eet\B7XX]. Source object: class org.jys.clepsydra.data.users.Admin [EMAIL PROTECTED]trHx` :=36,iVikR@testDocumentBase at org.apache.ojb.broker.util.ExceptionHelper.generateException(ExceptionHelper.java:161) at org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeInsert(JdbcAccessImpl.java:241) at org.apache.ojb.broker.core.PersistenceBrokerImpl.storeToDb(PersistenceBrokerImpl.java:2256) at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(PersistenceBrokerImpl.java:988) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(DelegatingPersistenceBroker.java:172) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(DelegatingPersistenceBroker.java:172) at org.apache.ojb.odmg.ObjectEnvelope.doInsert(ObjectEnvelope.java:767) at org.apache.ojb.odmg.states.StateNewDirty.commit(StateNewDirty.java:106) at org.apache.ojb.odmg.ObjectEnvelopeTable.writeAllEnvelopes(ObjectEnvelopeTable.java:249) at org.apache.ojb.odmg.ObjectEnvelopeTable.writeObjects(ObjectEnvelopeTable.java:185) at org.apache.ojb.odmg.TransactionImpl.doWriteObjects(TransactionImpl.java:384) at org.apache.ojb.odmg.TransactionImpl.prepareCommit(TransactionImpl.java:743) at org.apache.ojb.odmg.TransactionImpl.commit(TransactionImpl.java:679
Re: Foreign key not set
i'am getting the same error. i'am going to try to do it with a non abstract class maybe it can be that. Armin Waibel wrote: Could you try to set auto-update=link in 1:n reference of User and run your test again: collection-descriptor name=roles element-class-ref=org.jys.clepsydra.data.users.Role auto-update=link auto-delete=true inverse-foreignkey field-ref=userId/ /collection-descriptor regards Armin Jean-Yves Sironneau wrote: here is the extract of the repository file : Oups i think i forgot to explain that Role is an abstract class, and that Viewer inherits from Role, Author from Viewer and Admin from Author here are the classes too : public class Viewer extends Role { public Viewer(DocumentBase base) { super(base); } public Viewer() { super(); } } public class Author extends Viewer { public Author(DocumentBase base) { super(base); } public Author() { super(); } } public class Admin extends Author { public Admin(DocumentBase base) { super(base); } public Admin() { super(); } } class-descriptor class=org.jys.clepsydra.data.users.Admin table=Admin field-descriptor name=userId column=userId jdbc-type=VARCHAR nullable=false length=254 access=anonymous /field-descriptor field-descriptor name=documentBaseId column=documentBaseId jdbc-type=VARCHAR nullable=false length=254 access=anonymous /field-descriptor field-descriptor name=id column=id jdbc-type=VARCHAR primarykey=true length=254 /field-descriptor reference-descriptor name=documentBase class-ref=org.jys.clepsydra.data.DocumentBase auto-update=none auto-delete=none foreignkey field-ref=documentBaseId/ /reference-descriptor /class-descriptor class-descriptor class=org.jys.clepsydra.data.users.Author table=Author extent-class class-ref=org.jys.clepsydra.data.users.Admin/ field-descriptor name=userId column=userId jdbc-type=VARCHAR nullable=false length=254 access=anonymous /field-descriptor field-descriptor name=documentBaseId column=documentBaseId jdbc-type=VARCHAR nullable=false length=254 access=anonymous /field-descriptor field-descriptor name=id column=id jdbc-type=VARCHAR primarykey=true length=254 /field-descriptor reference-descriptor name=documentBase class-ref=org.jys.clepsydra.data.DocumentBase auto-update=none auto-delete=none foreignkey field-ref=documentBaseId/ /reference-descriptor /class-descriptor class-descriptor class=org.jys.clepsydra.data.users.Role table=Role extent-class class-ref=org.jys.clepsydra.data.users.Viewer/ field-descriptor name=userId column=userId jdbc-type=VARCHAR nullable=false length=254 access=anonymous /field-descriptor field-descriptor name=documentBaseId column=documentBaseId jdbc-type=VARCHAR nullable=false length=254 access=anonymous /field-descriptor field-descriptor name=id column=id jdbc-type=VARCHAR primarykey=true length=254 /field-descriptor reference-descriptor name=documentBase class-ref=org.jys.clepsydra.data.DocumentBase auto-update=none auto-delete=none foreignkey field-ref=documentBaseId/ /reference-descriptor /class-descriptor class-descriptor class=org.jys.clepsydra.data.users.User table=UUser field-descriptor name=id column=id jdbc-type=VARCHAR primarykey=true length=254 /field-descriptor field-descriptor name=creationDate column=creationDate jdbc-type=DATE /field-descriptor field-descriptor name=active column=active jdbc-type=BIT /field-descriptor field-descriptor name=name column=name jdbc-type=VARCHAR nullable=false length=254 /field-descriptor field-descriptor name=password column=password jdbc-type=VARCHAR nullable=false length=254 /field-descriptor field-descriptor name=applicationAdmin column=applicationAdmin jdbc-type=BIT /field-descriptor field-descriptor name=email column=email jdbc-type=VARCHAR length=254 /field-descriptor field-descriptor name=url column=url jdbc-type=VARCHAR length=254 /field-descriptor collection-descriptor name=roles element-class-ref=org.jys.clepsydra.data.users.Role auto-delete=true
Re: Foreign key not set
So i still don't get it, the workaround is to not use anonymous foreign key and to set the userId myself... As i don' t know in OJB where the anonymous key is supposed to be set i can't really try to find the bug for now, but i'll try to take a look. Thanks for your help. Jean-Yves Sironneau wrote: i'am getting the same error. i'am going to try to do it with a non abstract class maybe it can be that. Armin Waibel wrote: Could you try to set auto-update=link in 1:n reference of User and run your test again: collection-descriptor name=roles element-class-ref=org.jys.clepsydra.data.users.Role auto-update=link auto-delete=true inverse-foreignkey field-ref=userId/ /collection-descriptor regards Armin Jean-Yves Sironneau wrote: here is the extract of the repository file : Oups i think i forgot to explain that Role is an abstract class, and that Viewer inherits from Role, Author from Viewer and Admin from Author here are the classes too : public class Viewer extends Role { public Viewer(DocumentBase base) { super(base); } public Viewer() { super(); } } public class Author extends Viewer { public Author(DocumentBase base) { super(base); } public Author() { super(); } } public class Admin extends Author { public Admin(DocumentBase base) { super(base); } public Admin() { super(); } } class-descriptor class=org.jys.clepsydra.data.users.Admin table=Admin field-descriptor name=userId column=userId jdbc-type=VARCHAR nullable=false length=254 access=anonymous /field-descriptor field-descriptor name=documentBaseId column=documentBaseId jdbc-type=VARCHAR nullable=false length=254 access=anonymous /field-descriptor field-descriptor name=id column=id jdbc-type=VARCHAR primarykey=true length=254 /field-descriptor reference-descriptor name=documentBase class-ref=org.jys.clepsydra.data.DocumentBase auto-update=none auto-delete=none foreignkey field-ref=documentBaseId/ /reference-descriptor /class-descriptor class-descriptor class=org.jys.clepsydra.data.users.Author table=Author extent-class class-ref=org.jys.clepsydra.data.users.Admin/ field-descriptor name=userId column=userId jdbc-type=VARCHAR nullable=false length=254 access=anonymous /field-descriptor field-descriptor name=documentBaseId column=documentBaseId jdbc-type=VARCHAR nullable=false length=254 access=anonymous /field-descriptor field-descriptor name=id column=id jdbc-type=VARCHAR primarykey=true length=254 /field-descriptor reference-descriptor name=documentBase class-ref=org.jys.clepsydra.data.DocumentBase auto-update=none auto-delete=none foreignkey field-ref=documentBaseId/ /reference-descriptor /class-descriptor class-descriptor class=org.jys.clepsydra.data.users.Role table=Role extent-class class-ref=org.jys.clepsydra.data.users.Viewer/ field-descriptor name=userId column=userId jdbc-type=VARCHAR nullable=false length=254 access=anonymous /field-descriptor field-descriptor name=documentBaseId column=documentBaseId jdbc-type=VARCHAR nullable=false length=254 access=anonymous /field-descriptor field-descriptor name=id column=id jdbc-type=VARCHAR primarykey=true length=254 /field-descriptor reference-descriptor name=documentBase class-ref=org.jys.clepsydra.data.DocumentBase auto-update=none auto-delete=none foreignkey field-ref=documentBaseId/ /reference-descriptor /class-descriptor class-descriptor class=org.jys.clepsydra.data.users.User table=UUser field-descriptor name=id column=id jdbc-type=VARCHAR primarykey=true length=254 /field-descriptor field-descriptor name=creationDate column=creationDate jdbc-type=DATE /field-descriptor field-descriptor name=active column=active jdbc-type=BIT /field-descriptor field-descriptor name=name column=name jdbc-type=VARCHAR nullable=false length=254 /field-descriptor field-descriptor name=password column=password jdbc-type=VARCHAR nullable=false length=254 /field-descriptor field-descriptor name=applicationAdmin column=applicationAdmin jdbc-type=BIT /field-descriptor field-descriptor name=email column=email
Re: Foreign key not set
I can not keep trying right now, but i will tomorrow, the visible difference i see is that of storing the user i use the way : Transaction tx = getImplementation().newTransaction(); tx.begin(); db.makePersistent(o); tx.commit(); But the collections of roles is modified before that. Maybe i'am not doing it the right way, but it's working for all my other similar relations... Are we supposed to lock the object before any modification are made to it ? When i tried the way you did in the sample you give i get an exception org.apache.ojb.odmg.TransactionAbortedExceptionOJB: Can't commit objects: Unexpected behavior java.lang.RuntimeException: Unexpected behavior org.apache.ojb.odmg.ObjectEnvelopeTable.cascadeInsertSingleReferences(ObjectEnvelopeTable.java:602) org.apache.ojb.odmg.ObjectEnvelopeTable.cascadeInsertFor(ObjectEnvelopeTable.java:555) org.apache.ojb.odmg.ObjectEnvelopeTable.cascadeMarkedForInsert(ObjectEnvelopeTable.java:535) org.apache.ojb.odmg.ObjectEnvelopeTable.cascadingDependents(ObjectEnvelopeTable.java:504) Armin Waibel wrote: Jean-Yves Sironneau wrote: i'am getting the same error. i'am going to try to do it with a non abstract class maybe it can be that. I setup a similar test Implementation odmg = OJB.getInstance(); Database db = odmg.newDatabase(); db.open(null, Database.OPEN_READ_WRITE); BookShelf bookShelf = new BookShelf(prefix); TransactionExt tx = (TransactionExt) odmg.newTransaction(); tx.begin(); db.makePersistent(bookShelf); tx.commit(); tx.begin(); tx.lock(bookShelf, Transaction.WRITE); BookShelfItem ev1 = new DVD(bookShelf); BookShelfItem ev2 = new Book(bookShelf); bookShelf.addItem(ev1); bookShelf.addItem(ev2); tx.commit(); works fine! BookSelf has a 1:n to abstract class BookSelfItem and the test add a concrete objects to an existing BookSelf object. The FK is defined as anonymous field in the abstract class: class-descriptor class=org.apache.ojb.broker.CollectionTest$BookShelfItem extent-class class-ref=org.apache.ojb.broker.CollectionTest$Book/ extent-class class-ref=org.apache.ojb.broker.CollectionTest$DVD/ /class-descriptor class-descriptor class=org.apache.ojb.broker.CollectionTest$BookShelf table=COL_BOOKSHELFS ... collection-descriptor name=items element-class-ref=org.apache.ojb.broker.CollectionTest$BookShelfItem auto-retrieve=true inverse-foreignkey field-ref=shelfFk/ /collection-descriptor /class-descriptor class-descriptor class=org.apache.ojb.broker.CollectionTest$Book table=COL_BOOKS field-descriptor name=pk column=PK jdbc-type=INTEGER primarykey=true autoincrement=true / field-descriptor name=shelfFk column=BOOKSHELF_FK jdbc-type=INTEGER access=anonymous / reference-descriptor name=shelf class-ref=org.apache.ojb.broker.CollectionTest$BookShelf auto-retrieve=true auto-update=false auto-delete=false proxy=true foreignkey field-ref=shelfFk/ /reference-descriptor /class-descriptor Did you checked your test with a debugger? Is the PK of the User object populated with non null value? I don't know what's going on in your persistence layer, is User 't' locked before the admin is added? But something like that will work too: ... BookShelfItem ev1 = new DVD(bookShelf); BookShelfItem ev2 = new Book(bookShelf); bookShelf.addItem(ev1); bookShelf.addItem(ev2); tx.begin(); tx.lock(bookShelf, Transaction.READ); db.makePersistent(ev1); db.makePersistent(ev2); tx.commit(); Could you setup a test only using the odmg-api which reproduce your problem? regards, Armin Armin Waibel wrote: Could you try to set auto-update=link in 1:n reference of User and run your test again: collection-descriptor name=roles element-class-ref=org.jys.clepsydra.data.users.Role auto-update=link auto-delete=true inverse-foreignkey field-ref=userId/ /collection-descriptor regards Armin Jean-Yves Sironneau wrote: here is the extract of the repository file : Oups i think i forgot to explain that Role is an abstract class, and that Viewer inherits from Role, Author from Viewer and Admin from Author here are the classes too : public class Viewer extends Role { public Viewer(DocumentBase base) { super(base); } public Viewer() { super(); } } public class Author extends Viewer { public Author(DocumentBase base) { super(base); } public Author() { super(); } } public class Admin extends Author { public Admin(DocumentBase base) { super(base); } public Admin() { super(); } } class-descriptor class=org.jys.clepsydra.data.users.Admin table=Admin field-descriptor name=userId column=userId jdbc-type=VARCHAR nullable=false length=254 access=anonymous /field-descriptor