You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Joose Vettenranta <jo...@iki.fi> on 2004/07/20 11:38:32 UTC

ojb + forms = I can't get it to work

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


Re: ojb + forms = I can't get it to work

Posted by Joose Vettenranta <jo...@iki.fi>.
I got it to work! Woot woot!

But I don't know what I did, but I'll keep poking around to make it 
work even better..

- Joose

20.7.2004 kello 16:48, Joose Vettenranta kirjoitti:

  WEll, the story continues.. I was able to enhance that class and it 
did make it to work.. Well, but I got a new error, so the sequal of 
this story is about to be reveiled:
>
> The new story is called:
>
> org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException: 
> Can not init Identity for given object
>
> - Joose
>
> 20.7.2004 kello 16:10, Joose Vettenranta kirjoitti:
>
>  I forgot to say that I have not enhanced the new classes. Could this 
> be a problem? If yes, how to enhance it then?
>
> --
> "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
>
>
--
"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


Re: ojb + forms = I can't get it to work

Posted by Tony Collen <co...@umn.edu>.
Antonio Gallardo wrote:


> 
> Nope. The problem was no enhanced classes. Anyway I think he finally made
> it work.
> 

Doh, whoops, I was looking at the message at the end of the error 
instead of the name of the exception.. now it is clear ;)

Tony


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


Re: ojb + forms = I can't get it to work

Posted by Antonio Gallardo <ag...@agssa.net>.
Tony Collen dijo:
> Joose Vettenranta wrote:
>
>> WEll, the story continues.. I was able to enhance that class and it did
>> make it to work.. Well, but I got a new error, so the sequal of this
>> story is about to be reveiled:
>>
>> The new story is called:
>>
>> org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException: Can
>> not init Identity for given object
>
> I could be totally wrong since I haven't done a lot of OJB stuff, but I
> think it has to do with your database table not having a unique key field.

Nope. The problem was no enhanced classes. Anyway I think he finally made
it work.

Best Regards,

Antonio Gallardo


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


Re: ojb + forms = I can't get it to work [SOLVED]

Posted by Joose Vettenranta <jo...@iki.fi>.
After 2 days of trying different options and stuff, I found the  
solution!

Solution is that connection has to be defined to have  
platform="Postgresql" and subprotocol="postgresql" and then I can use  
autoincrement="true" field thingie!

Here is the complete repository.xml for those strugling on same problem:

<descriptor-repository version="1.0" isolation-level="read-uncommitted">
     <jdbc-connection-descriptor jcd-alias="<name in cocoon.xconf for  
this connection>" default-connection="true"
platform="PostgreSQL"
subprotocol="postgresql"
 >
<sequence-manager  
className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImp 
l" />
</jdbc-connection-descriptor>

     <class-descriptor class="net.vettenranta.category.bean.Category"  
table="categories">
         <field-descriptor name="id"
                           jdbc-type="INTEGER"
                           primarykey="true"
                           default-fetch="true"
                           access="readonly"
indexed="true" autoincrement="true"
                           sequence-name="categories_id_seq"
                           column="id" />
         <field-descriptor name="parent" column="parent"  
jdbc-type="INTEGER"/>
     </class-descriptor>
</descriptor-repository>

- 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


Re: ojb + forms = I can't get it to work

Posted by Joose Vettenranta <jo...@iki.fi>.
Hi,

20.7.2004 kello 21:02, Tony Collen kirjoitti:

  Joose Vettenranta wrote:
>> WEll, the story continues.. I was able to enhance that class and it  
>> did make it to work.. Well, but I got a new error, so the sequal of  
>> this story is about to be reveiled:
>> The new story is called:
>> org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException:  
>> Can not init Identity for given object
> I could be totally wrong since I haven't done a lot of OJB stuff, but  
> I think it has to do with your database table not having a unique key  
> field.

This is not the case.

in postgresql I created the database like this:
create table category (
  id serial,
  parent integer,
primary key(id),
foreign key(parent) references category(id)
);

I tried also with create index but that didn't help. So there is unique  
key in database!

I didn't find how I could define jdo something as unique or  
autoincrement or as index, so I just have:

   <class name="Category" identity-type="datastore">
    <extension vendor-name="ojb" key="table" value="product_categories"/>
    <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>
   </class>


I think the problem might be in repository.xml or something like that.

in repository.xml I have:

     <class-descriptor class="net.vettenranta.Category"  
table="product_categories">
         <field-descriptor name="id"
                           jdbc-type="INTEGER"
                           primarykey="true"
                           default-fetch="true"
                           access="readonly"
                           autoincrement="true"
                           indexed="true"
                           sequence-name="product_categories_id_seq"
                           column="id" />
         <field-descriptor name="parent" column="parent"  
jdbc-type="INTEGER"/>
     </class-descriptor>

if I take "autoincrement" away, it works, but doesn't get the id of the  
row just inserted. And when using autoincrement="true" I get:
----
org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException: Can  
not init Identity for given object  
net.vettenranta.category.bean.Category@637194d
...
Caused by: org.apache.ojb.broker.PersistenceBrokerException: Could not  
get key value
Caused by: org.apache.ojb.broker.util.sequence.SequenceManagerException:
Could not grab next id, failed with
This feature is not supported by this implementation
Creation of new sequence failed with
This feature is not supported by this implementation
...
Caused by: java.lang.UnsupportedOperationException: This feature is not  
supported by this implementation
-----


see full stacktrace below:

Original Exception:  
org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException: Can  
not init Identity for given object  
net.vettenranta.category.bean.Category@637194d
         at org.apache.ojb.broker.Identity.init(Identity.java:125)
         at org.apache.ojb.broker.Identity.<init>(Identity.java:82)
         at  
org.apache.ojb.jdori.sql.OjbStoreManager.createObjectId(OjbStoreManager. 
java:223)
         at  
com.sun.jdori.common.state.StateManagerImpl.initializeSM(Unknown  
Source)
         at  
com.sun.jdori.common.state.StateManagerImpl.makePersistent(Unknown  
Source)
         at com.sun.jdori.common.CacheManagerImpl.makePersistent(Unknown  
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)
         at  
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav 
a:79)
         at  
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor 
Impl.java(Compiled Code))
         at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
         at  
org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:230)
         at  
org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1244)
         at  
org.mozilla.javascript.continuations.ContinuationInterpreter.interpret(C 
ontinuationInterpreter.java:1134)
         at  
org.mozilla.javascript.continuations.ContinuationInterpreter.interpret(C 
ontinuationInterpreter.java:190)
         at  
org.mozilla.javascript.continuations.ContinuationInterpreter.interpret(C 
ontinuationInterpreter.java:138)
         at  
org.mozilla.javascript.continuations.InterpretedFunctionImpl.call(Interp 
retedFunctionImpl.java:121)
         at  
org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1244)
         at  
org.mozilla.javascript.ScriptableObject.callMethod(ScriptableObject.java 
:1591)
         at  
org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterpret 
er.handleContinuation(FOM_JavaScriptInterpreter.java:788)
         at  
org.apache.cocoon.components.treeprocessor.sitemap.CallFunctionNode.invo 
ke(CallFunctionNode.java:120)
         at  
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode. 
invokeNodes(AbstractParentProcessingNode.java:49)
         at  
org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.i 
nvoke(PreparableMatchNode.java:130)
         at  
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode. 
invokeNodes(AbstractParentProcessingNode.java:72)
         at  
org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(P 
ipelineNode.java:126)
         at  
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode. 
invokeNodes(AbstractParentProcessingNode.java:72)
         at  
org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke( 
PipelinesNode.java:101)
         at  
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreePro 
cessor.java:336)
         at  
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreePro 
cessor.java:277)
         at  
org.apache.cocoon.components.treeprocessor.sitemap.MountNode.invoke(Moun 
tNode.java:103)
         at  
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode. 
invokeNodes(AbstractParentProcessingNode.java:49)
         at  
org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.i 
nvoke(PreparableMatchNode.java:130)
         at  
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode. 
invokeNodes(AbstractParentProcessingNode.java:72)
         at  
org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(P 
ipelineNode.java:126)
         at  
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode. 
invokeNodes(AbstractParentProcessingNode.java:72)
         at  
org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke( 
PipelinesNode.java:101)
         at  
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreePro 
cessor.java:336)
         at  
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreePro 
cessor.java:277)
         at org.apache.cocoon.Cocoon.process(Cocoon.java:639)
         at  
org.apache.cocoon.servlet.CocoonServlet.service(CocoonServlet.java: 
1098)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at  
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:354)
         at  
org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationH 
andler.java:294)
         at  
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java: 
567)
         at org.mortbay.http.HttpContext.handle(HttpContext.java:1808)
         at  
org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationCon 
text.java:525)
         at org.mortbay.http.HttpContext.handle(HttpContext.java:1758)
         at org.mortbay.http.HttpServer.service(HttpServer.java:879)
         at  
org.mortbay.http.HttpConnection.service(HttpConnection.java:790)
         at  
org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:952)
         at  
org.mortbay.http.HttpConnection.handle(HttpConnection.java:807)
         at  
org.mortbay.http.SocketListener.handleConnection(SocketListener.java: 
197)
         at  
org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
         at  
org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:501)
Caused by: org.apache.ojb.broker.PersistenceBrokerException: Could not  
get key value
         at  
org.apache.ojb.broker.util.BrokerHelper.getAutoIncrementValue(BrokerHelp 
er.java:315)
         at  
org.apache.ojb.broker.util.BrokerHelper.getValuesForObject(BrokerHelper. 
java:347)
         at  
org.apache.ojb.broker.util.BrokerHelper.getKeyValues(BrokerHelper.java: 
173)
         at org.apache.ojb.broker.Identity.init(Identity.java:118)
         ... 56 more
Caused by: org.apache.ojb.broker.util.sequence.SequenceManagerException:
Could not grab next id, failed with
This feature is not supported by this implementation
Creation of new sequence failed with
This feature is not supported by this implementation

         at  
org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl.getUnique 
Long(SequenceManagerNextValImpl.java:135)
         at  
org.apache.ojb.broker.util.sequence.AbstractSequenceManager.getUniqueVal 
ue(AbstractSequenceManager.java:128)
         at  
org.apache.ojb.broker.util.BrokerHelper.getAutoIncrementValue(BrokerHelp 
er.java:302)
         ... 59 more
Caused by: java.lang.UnsupportedOperationException: This feature is not  
supported by this implementation
         at  
org.apache.ojb.broker.platforms.PlatformDefaultImpl.createSequenceQuery( 
PlatformDefaultImpl.java:264)
         at  
org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl.createSeq 
uence(SequenceManagerNextValImpl.java:201)
         at  
org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl.getUnique 
Long(SequenceManagerNextValImpl.java:131)
         ... 61 more


- 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


Re: ojb + forms = I can't get it to work

Posted by Tony Collen <co...@umn.edu>.
Joose Vettenranta wrote:

> WEll, the story continues.. I was able to enhance that class and it did 
> make it to work.. Well, but I got a new error, so the sequal of this 
> story is about to be reveiled:
> 
> The new story is called:
> 
> org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException: Can 
> not init Identity for given object

I could be totally wrong since I haven't done a lot of OJB stuff, but I 
think it has to do with your database table not having a unique key field.


Tony


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


Re: ojb + forms = I can't get it to work

Posted by Joose Vettenranta <jo...@iki.fi>.
WEll, the story continues.. I was able to enhance that class and it did 
make it to work.. Well, but I got a new error, so the sequal of this 
story is about to be reveiled:

The new story is called:

org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException: Can 
not init Identity for given object

- Joose

20.7.2004 kello 16:10, Joose Vettenranta kirjoitti:

  I forgot to say that I have not enhanced the new classes. Could this 
be a problem? If yes, how to enhance it then?

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


Re: ojb + forms = I can't get it to work

Posted by Joose Vettenranta <jo...@iki.fi>.
I forgot to say that I have not enhanced the new classes. Could this be 
a problem? If yes, how to enhance it then?

- Joose

> Original Exception: javax.jdo.JDOUserException: Object not 
> PersistenceCapable.

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