Re: Foreign key not set

2005-10-26 Thread Armin Waibel

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)
   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 

Re: Foreign key not set

2005-10-26 Thread Jean-Yves Sironneau

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
   
   inverse-foreignkey field-ref=userId/
   /collection-descriptor
/class-descriptor
class-descriptor
   class=org.jys.clepsydra.data.users.Viewer
   table=Viewer

   extent-class class-ref=org.jys.clepsydra.data.users.Author/
   field-descriptor
   name=userId
   column=userId
   jdbc-type=VARCHAR
   nullable=false
   length=254
   access=anonymous
   
   /field-descriptor
   field-descriptor
   name=documentBaseId
   

Re: Foreign key not set

2005-10-26 Thread Armin Waibel
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
   
   inverse-foreignkey field-ref=userId/
   /collection-descriptor
/class-descriptor
class-descriptor
   

Re: Foreign key not set

2005-10-26 Thread Jean-Yves Sironneau

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

2005-10-26 Thread Armin Waibel

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
   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
   

Re: Foreign key not set

2005-10-26 Thread Jean-Yves Sironneau
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

2005-10-26 Thread Armin Waibel

Hi again,

a correction of my previous post (I don't realized that you use the 
odmg-api). In the new upcoming version you have to set 
auto-update=none and auto-delete=none or object when using the 
odmg-api.


collection-descriptor
name=roles
element-class-ref=org.jys.clepsydra.data.users.Role
auto-update=none
auto-delete=none or object

inverse-foreignkey field-ref=userId/
/collection-descriptor

regards,
Armin

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
   

Re: Foreign key not set

2005-10-26 Thread Jean-Yves Sironneau
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