cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joose Vettenranta <jo...@iki.fi>
Subject ojb + forms = I can't get it to work
Date Tue, 20 Jul 2004 09:38:32 GMT
Using cocoon 2.1.5.1 and jdo 1.0.1

sample/blocks/ojb/ Works OK

I tried to rip that code from there, but wasn't able to. (btw, if you  
make an sample of something, try to avoid default things, because then  
when trying to learn from that, the default values always make thins  
more difficult, like defaultBroker -stuff).

I tried to rip that sample code and code from wiki, but ended up with  
error "Object not PersistenceCapable".

(I'm trying to do insert to database a new row like this: insert  
category(parent) value({value from form}).. and then use that ID from  
that serial-field later. (so it has to be somehow fetched to that  
bean)..

Here is all the files:

Postgresql has next field:
------
create table category (
  id serial,
  parent integer,
primary key(id),
foreign key (parent) references category(id));
-------

flowscript is like this:
-------
cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/ 
Form.js");

function category () {
         var factory =  
cocoon.getComponent(Packages.org.apache.cocoon.ojb.jdo.components.JdoPMF 
.ROLE);
         var bean = new Packages.net.vettenranta.category.Category();
         var dao = new Packages.net.vettenranta.category.CategoryDAO();
         var form = new Form("defs/forms/category.xml");
         form.createBinding("defs/forms/category-binding.xml");
         form.load(bean); // formi ladataan beanin arvoilla
         form.showForm("internal/category/edit.html"); // editoi
         form.save(bean); // tallenna formin data beaniin
         dao.insert(bean, factory); // kirjoita bean levylle..
         cocoon.releaseComponent(factory); // factoryista eroon...
}
--------------

CategoryDAO.java
------
package net.vettenranta.category;

import javax.jdo.PersistenceManager;
import javax.jdo.Transaction;

import org.apache.cocoon.ojb.jdo.components.JdoPMF;
import org.apache.ojb.broker.Identity;
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.PersistenceBrokerFactory;

import net.vettenranta.category.Category;

public class CategoryDAO {
     public CategoryDAO () { }

     public void insert(Category cat, JdoPMF pmf) {
         PersistenceManager persistenceManager =  
pmf.getPersistenceManager();
         Transaction tx = persistenceManager.currentTransaction();
         tx.begin();
         persistenceManager.makePersistent (cat);
         tx.commit();
     }
}
------

Category.java:
-------
package net.vettenranta.category;
import java.io.Serializable;
public class Category implements Serializable {
         protected int parent;
         private int id;

         public Category () { this.id = 0; this.parent = 0; }
         public void setId (int id) { this.id = id; }
         public int getId () { return this.id; }
         public void setParent (int parent) { this.parent = parent; }
}
----------

category-binding.xml:
-----------------
<fb:context xmlns:fb="http://apache.org/cocoon/forms/1.0#binding"  
path="/" >
  <fb:value id="parent" path="parent" />
</fb:context>
-----------------

repository.xml (snip) (WEB-INF/classes/reposity.xml):
-----------------
     <jdbc-connection-descriptor jcd-alias="category" />

     <class-descriptor class="net.vettenranta.category.Category"  
table="category">
         <field-descriptor name="id"   column="ID"   jdbc-type="INTEGER"  
primarykey="true"/>
         <field-descriptor name="parent" column="parent"  
jdbc-type="INTEGER"/>
     </class-descriptor>
-----------

OJB.properties (snip):
----------
ConnectionFactoryClass=org.apache.cocoon.ojb.components.ConnectionFactor 
yAvalonDataSource
----------

mytest.ojb (WEB-INF/classes/)
---------
<jdo>
     <package name="net.vettenranta.category">
          <class name="Category" identity-type="datastore">
             <extension vendor-name="ojb" key="table" value="category"/>
             <field name="id" persistence-modifier="persistent">
                 <extension vendor-name="ojb" key="column" value="ID"/>
             </field>
             <field name="parent" persistence-modifier="persistent">
                 <extension vendor-name="ojb" key="column"  
value="parent"/>
             </field>
  </package>
</jdo>
--------

Now when I try to add that form to database, I get error message on  
that dao.insert (bean, factory):

javax.jdo.JDOUserException: Object not PersistenceCapable.  
FailedObject:net.vettenranta.category.Category@e21ed3b

Original Exception: javax.jdo.JDOUserException: Object not  
PersistenceCapable.
FailedObject:net.vettenranta.category.Category@e21ed3b
	at  
com.sun.jdori.common.PersistenceManagerImpl.assertPersistenceCapable(Unk 
nown Source)
	at  
com.sun.jdori.common.PersistenceManagerImpl.makePersistentInternal(Unkno 
wn Source)
	at com.sun.jdori.common.PersistenceManagerImpl.makePersistent(Unknown  
Source)
	at  
com.sun.jdori.common.PersistenceManagerWrapper.makePersistent(Unknown  
Source)
	at net.vettenranta.category.CategoryDAO.insert(CategoryDAO.java:46)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

And that line 46 is this:

         persistenceManager.makePersistent (cat);


What do I do wrong? And how/where I tell that category is using  
database? (in cocoon.xconf there is connection named category also).

Thanks, Joose

--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message