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


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 List<Role> roles = new Vector<Role>();
*
   /**
    * @ojb.field
    */
   private String url;

  public User(String name) {
       this.name = name;
   }

   public User() {
       super();
   }


   /**
    * @return Returns the roles.
    */
   public List<Role> 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=3eg3Lc&b;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 org.jys.ui.tapestry.ApplicationServlet.constructRegistry(ApplicationServlet.java:23) at org.apache.tapestry.ApplicationServlet.init(ApplicationServlet.java:212) at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:383) at org.mortbay.jetty.servlet.ServletHolder.start(ServletHolder.java:243) at org.mortbay.jetty.servlet.ServletHandler.initializeServlets(ServletHandler.java:446) at org.mortbay.jetty.servlet.WebApplicationHandler.initializeServlets(WebApplicationHandler.java:321) at org.mortbay.jetty.servlet.WebApplicationContext.doStart(WebApplicationContext.java:511)
   at org.mortbay.util.Container.start(Container.java:72)
   at org.mortbay.http.HttpServer.doStart(HttpServer.java:753)
   at org.mortbay.util.Container.start(Container.java:72)
at com.iw.plugins.jettyrunner.PluginRunner.launch(PluginRunner.java:282) at com.iw.plugins.jettyrunner.PluginRunner.launch(PluginRunner.java:104) at com.iw.plugins.jettyrunner.PluginRunner.main(PluginRunner.java:75) Caused by: java.sql.SQLException: ERREUR: Une valeur NULL dans la colonne «userid» viole la contrainte NOT NULL at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1365) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1160) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:172) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:387) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:328) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:280)
   at org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeIn



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





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to